apple/pkl · error · VmException

noOuterScope

noOuterScope

Error message

Top-level scope does not have an outer scope.

What it means

Pkl's `outer` expression refers to the receiver of the lexically enclosing object. When evaluated in a context whose owner chain has no enclosing receiver — i.e. the current scope is top-level — OuterNode throws noOuterScope because there is no outer scope to reference.

Solutions

  1. Remove the `outer` reference at top level and address the value directly (top-level properties are already module scope)
  2. Move the code that uses `outer` inside an actual object member so an enclosing receiver exists
  3. Replace `outer.foo` with a direct reference to the module property `foo`
  4. If inside a class, reference the intended property without `outer` or pass the value as a parameter

Example fix

// before (module level)
x = 1
y = outer.x + 1 // ERROR: no outer scope
// after
x = 1
y = x + 1
Defensive patterns

Strategy: type-guard

Validate before calling

// only use `outer` inside object members, never at module top level
// bad:  y = outer.x   (module level)
// good: inside an object member: y = outer.x

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: Using the `outer` keyword at the top level of a module (module body), or inside a top-level function/class member whose owner has getEnclosingReceiver() == null, i.e. any place where VmUtils.getOwner(frame).getEnclosingReceiver() returns null.

Common situations: Writing `outer.x` in a module-level property; pasting an object-member snippet that uses `outer` into the top level of a .pkl file; using `outer` inside a class definition where there is no enclosing object literal.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at pkl-core/src/main/java/org/pkl/core/ast/expression/primary/OuterNode.java:39

import com.oracle.truffle.api.source.SourceSection;
import org.pkl.core.ast.ExpressionNode;
import org.pkl.core.runtime.VmUtils;

// TODO: should `outer.x` work like `super.x`? (start search in enclosing scope)
// TODO: if enclosing scope is lambda scope, can't use `lambda.x` to access lambda param `x`
@NodeInfo(shortName = "outer")
public final class OuterNode extends ExpressionNode {

  public OuterNode(SourceSection sourceSection) {
    super(sourceSection);
  }

  @Override
  public Object executeGeneric(VirtualFrame frame) {
    var outer = VmUtils.getOwner(frame).getEnclosingReceiver();
    if (outer == null) {
      CompilerDirectives.transferToInterpreter();
      throw exceptionBuilder().evalError("noOuterScope").build();
    }
    return outer;
  }
}

View on GitHub (pinned to f3efcbfc9b)