{"record":{"id":"3b197612446824e3","repo":"apple/pkl","slug":"defaultmember","errorCode":null,"errorMessage":"defaultMember","messagePattern":"defaultMember","errorType":"error_code","errorClass":"VmReferenceAccessError","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/runtime/VmReference.java","lineNumber":221,"sourceCode":"      checkCandidate.accept(t, candidates);\n    }\n    return new VmReference(domain, data, path.append(makeAccess.get()), minimizeTypes(candidates));\n  }\n\n  @SuppressWarnings(\"DuplicatedCode\")\n  private static void getCandidatePropertyType(PType type, String property, Set<PType> result) {\n    if (type == PType.UNKNOWN) {\n      result.add(type);\n      return;\n    }\n    // restriction: only class types can have their properties referenced\n    if (!(type instanceof PType.Class clazz)) {\n      throw new VmReferenceAccessError(type, VmReferenceAccessErrorType.CANNOT_FIND_MEMBER);\n    }\n    if (clazz.getPClass().getInfo() == PClassInfo.Dynamic) {\n      if (property.equals(\"default\")) {\n        // restriction: cannot reference Dynamic.default\n        throw new VmReferenceAccessError(type, VmReferenceAccessErrorType.DEFAULT_MEMBER);\n      }\n      result.add(PType.UNKNOWN);\n      return;\n    }\n    // restriction: cannot reference Listing/Mapping.default\n    if (clazz.getPClass().getInfo() == PClassInfo.Listing\n        || clazz.getPClass().getInfo() == PClassInfo.Mapping) {\n      var errorType =\n          property.equals(\"default\")\n              ? VmReferenceAccessErrorType.DEFAULT_MEMBER\n              : VmReferenceAccessErrorType.CANNOT_FIND_MEMBER;\n      throw new VmReferenceAccessError(type, errorType);\n    }\n    var baseModule = BaseModule.getModuleClass().export();\n    // restriction: cannot reference Module.output.\n    //   generalized: properties originally defined in external classes; the only extant example.\n    // This is implemented specifically because this is the only case where an external class\n    //   containing a property can be subclassed.","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/runtime/VmReference.java#L203-L239","documentation":"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.","triggerScenarios":"Accessing or referencing `someDynamic.default` where someDynamic has static type Dynamic, via property-reference checking.","commonSituations":"Trying to propagate or copy the `default` value of a Dynamic object in config code; accidentally writing `.default` on an untyped (Dynamic) object.","solutions":["Remove the `.default` reference; Dynamic.default is not referenceable.","If you need the default value, restructure the object so its value lives in a named property.","Give the object a concrete class type and reference that property instead.","Use a function or explicit property to share the underlying value."],"exampleFix":"// before\nv = someDynamic.default\n// after\nv = someDynamic\n// or reference a named property\nv = someDynamic.value","handlingStrategy":"type-guard","validationCode":"// Pkl: guard against referencing .default on Dynamic\nif (obj is Dynamic) { /* do not touch obj.default */ }","typeGuard":"// Pkl\nfunction hasNamedProp(obj: Dynamic, name: String): Boolean = name in obj.getClass().getAllProperties().keys","tryCatchPattern":"try {\n  eval(src);\n} catch (EvalException e) {\n  if (e.getMessage().contains(\"defaultMember\")) {\n    // remove the `.default` reference on the Dynamic object\n  }\n}","preventionTips":["Never write `.default` on Dynamic-typed values.","Expose needed values via named properties instead of relying on default.","Give objects concrete class types so typos surface as clearer errors."],"tags":["pkl","dynamic","default-property","reference"],"backgroundTag":"unsupported-operation","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}