apple/pkl · error · VmReferenceAccessError

defaultMember/cannotFindMember

Error message

defaultMember/cannotFindMember

What it means

Raised for property-reference access on Listing or Mapping objects: the `default` property of these collection types is not referenceable, and no other property exists on Listing/Mapping, so any property access yields either defaultMember (for `.default`) or cannotFindMember (anything else).

Source

Thrown at pkl-core/src/main/java/org/pkl/core/runtime/VmReference.java:233

    if (!(type instanceof PType.Class clazz)) {
      throw new VmReferenceAccessError(type, VmReferenceAccessErrorType.CANNOT_FIND_MEMBER);
    }
    if (clazz.getPClass().getInfo() == PClassInfo.Dynamic) {
      if (property.equals("default")) {
        // restriction: cannot reference Dynamic.default
        throw new VmReferenceAccessError(type, VmReferenceAccessErrorType.DEFAULT_MEMBER);
      }
      result.add(PType.UNKNOWN);
      return;
    }
    // restriction: cannot reference Listing/Mapping.default
    if (clazz.getPClass().getInfo() == PClassInfo.Listing
        || clazz.getPClass().getInfo() == PClassInfo.Mapping) {
      var errorType =
          property.equals("default")
              ? VmReferenceAccessErrorType.DEFAULT_MEMBER
              : VmReferenceAccessErrorType.CANNOT_FIND_MEMBER;
      throw new VmReferenceAccessError(type, errorType);
    }
    var baseModule = BaseModule.getModuleClass().export();
    // restriction: cannot reference Module.output.
    //   generalized: properties originally defined in external classes; the only extant example.
    // This is implemented specifically because this is the only case where an external class
    //   containing a property can be subclassed.
    // And this can't check prop.getOwner().isExternal() because fully overriding the property with
    //   a new type annotation means the owner isn't Module.
    if (clazz.getPClass().isSubclassOf(baseModule) && property.equals("output")) {
      throw new VmReferenceAccessError(
          new PType.Class(baseModule), VmReferenceAccessErrorType.EXTERNAL_CLASS);
    }

    // dot access on `Reference<D, Null>` gives `Reference<D, Null>`
    if (clazz.getPClass().getInfo() == PClassInfo.Null) {
      result.add(clazz);
      return;
    }

View on GitHub (pinned to f3efcbfc9b)

Solutions

  1. Use subscript access (`myMapping["key"]`) instead of property access for mappings.
  2. Do not reference `.default` on Listing/Mapping — it is inaccessible.
  3. If you need element defaults, restructure the Pkl code (e.g. a function returning a default element).
  4. For Listing, use indexing `myListing[0]` rather than property syntax.

Example fix

// before
x = myMapping.default
// after
x = myMapping["someKey"]
Defensive patterns

Strategy: type-guard

Validate before calling

// Pkl: use subscripts for collections, never property access
assert (myMapping is Mapping)
value = myMapping["key"]

Type guard

// Pkl
function isKeyedCollection(x: Any): Boolean = x is Mapping || x is Map

Try / catch

try {
  eval(src);
} catch (EvalException e) {
  if (e.getMessage().contains("defaultMember")) {
    // replace listing/mapping `.default` access with subscript access
  }
}

Prevention

When it happens

Trigger: Referencing `someListing.default`, `someMapping.default`, or any named property on a value statically typed as Listing or Mapping.

Common situations: Attempting `myMapping.default` to get a default element; typos like accessing a nonexistent key as a property instead of a subscript (`myMapping["key"]`).

Related errors


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