apple/pkl · error · VmReferenceAccessError

defaultMember

Error message

defaultMember

What it means

Raised when a `Reference`-style property access tries to reference the `default` property of a Dynamic object. Dynamic.default is a special hidden property that cannot be referenced by users, so Pkl blocks it with the defaultMember access error.

Source

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

      checkCandidate.accept(t, candidates);
    }
    return new VmReference(domain, data, path.append(makeAccess.get()), minimizeTypes(candidates));
  }

  @SuppressWarnings("DuplicatedCode")
  private static void getCandidatePropertyType(PType type, String property, Set<PType> result) {
    if (type == PType.UNKNOWN) {
      result.add(type);
      return;
    }
    // restriction: only class types can have their properties referenced
    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.

View on GitHub (pinned to f3efcbfc9b)

Solutions

  1. Remove the `.default` reference; Dynamic.default is not referenceable.
  2. If you need the default value, restructure the object so its value lives in a named property.
  3. Give the object a concrete class type and reference that property instead.
  4. Use a function or explicit property to share the underlying value.

Example fix

// before
v = someDynamic.default
// after
v = someDynamic
// or reference a named property
v = someDynamic.value
Defensive patterns

Strategy: type-guard

Validate before calling

// Pkl: guard against referencing .default on Dynamic
if (obj is Dynamic) { /* do not touch obj.default */ }

Type guard

// Pkl
function hasNamedProp(obj: Dynamic, name: String): Boolean = name in obj.getClass().getAllProperties().keys

Try / catch

try {
  eval(src);
} catch (EvalException e) {
  if (e.getMessage().contains("defaultMember")) {
    // remove the `.default` reference on the Dynamic object
  }
}

Prevention

When it happens

Trigger: Accessing or referencing `someDynamic.default` where someDynamic has static type Dynamic, via property-reference checking.

Common situations: Trying to propagate or copy the `default` value of a Dynamic object in config code; accidentally writing `.default` on an untyped (Dynamic) object.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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