apple/pkl · error · VmException

invalidThisTypeInTypeAlias

invalidThisTypeInTypeAlias

Error message

invalidThisTypeInTypeAlias

What it means

AstBuilder.visitThisType throws 'invalidThisTypeInTypeAlias': `this` types (e.g. in type annotations) are not permitted inside a type alias, since a typealias has no receiver. The input at fault is a `this` type reference appearing in a typealias declaration.

Solutions

  1. Replace the `this` type in the typealias with a concrete class type.
  2. Move the type annotation into a class or module where a receiver exists.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java:453 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08). Data as JSON: /api/errors/fffcf10467d37390. Report an issue: GitHub.

Appendix: source

Thrown at pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java:453

    var sourceSection = createSourceSection(type);
    // need to pass explicit class name for property and method arg/return type annotations.
    // this is because type annotations on class properties/methods are initialized when the
    // ClassNode
    // is executed, and the frame's receiver is the enclosing module rather than the class.
    // do not need: when in any object or at the module level (where `this` is the receiver's class)
    org.pkl.core.runtime.Identifier className = null;
    for (var scope = symbolTable.getCurrentScope(); scope != null; scope = scope.getParent()) {
      if (scope.isObjectScope() || scope.isCustomThisScope()) {
        break;
      }
      if (scope instanceof ClassScope foundClassScope) {
        className = foundClassScope.getName();
        break;
      }
      // it's still safe to break on ObjectScope because this is valid:
      // typealias Foo = List(any((it) -> it == new Dynamic { it is this })) // this == Dynamic
      if (scope.isTypeAliasScope()) {
        throw exceptionBuilder()
            .withSourceSection(sourceSection)
            .evalError("invalidThisTypeInTypeAlias")
            .build();
      }
    }

    ExpressionNode getClassNode;
    if (isBaseModule && className != null) {
      getClassNode = new GetBaseModuleClassNode(className);
    } else if (className == null) {
      getClassNode = new GetReceiverClassNode(sourceSection);
    } else if (className.isLocalProp()) {
      getClassNode =
          new ReadQualifiedLocalPropertyNode(
              sourceSection, className, false, new GetModuleNode(sourceSection));
    } else {
      getClassNode =
          ReadPropertyNodeGen.create(

View on GitHub (pinned to f3efcbfc9b)