{"record":{"id":"66a28b63b51087ed","repo":"apple/pkl","slug":"defaultmember-cannotfindmember","errorCode":null,"errorMessage":"defaultMember/cannotFindMember","messagePattern":"defaultMember/cannotFindMember","errorType":"error_code","errorClass":"VmReferenceAccessError","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/runtime/VmReference.java","lineNumber":233,"sourceCode":"    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.\n    // And this can't check prop.getOwner().isExternal() because fully overriding the property with\n    //   a new type annotation means the owner isn't Module.\n    if (clazz.getPClass().isSubclassOf(baseModule) && property.equals(\"output\")) {\n      throw new VmReferenceAccessError(\n          new PType.Class(baseModule), VmReferenceAccessErrorType.EXTERNAL_CLASS);\n    }\n\n    // dot access on `Reference<D, Null>` gives `Reference<D, Null>`\n    if (clazz.getPClass().getInfo() == PClassInfo.Null) {\n      result.add(clazz);\n      return;\n    }","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/runtime/VmReference.java#L215-L251","documentation":"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).","triggerScenarios":"Referencing `someListing.default`, `someMapping.default`, or any named property on a value statically typed as Listing or Mapping.","commonSituations":"Attempting `myMapping.default` to get a default element; typos like accessing a nonexistent key as a property instead of a subscript (`myMapping[\"key\"]`).","solutions":["Use subscript access (`myMapping[\"key\"]`) instead of property access for mappings.","Do not reference `.default` on Listing/Mapping — it is inaccessible.","If you need element defaults, restructure the Pkl code (e.g. a function returning a default element).","For Listing, use indexing `myListing[0]` rather than property syntax."],"exampleFix":"// before\nx = myMapping.default\n// after\nx = myMapping[\"someKey\"]","handlingStrategy":"type-guard","validationCode":"// Pkl: use subscripts for collections, never property access\nassert (myMapping is Mapping)\nvalue = myMapping[\"key\"]","typeGuard":"// Pkl\nfunction isKeyedCollection(x: Any): Boolean = x is Mapping || x is Map","tryCatchPattern":"try {\n  eval(src);\n} catch (EvalException e) {\n  if (e.getMessage().contains(\"defaultMember\")) {\n    // replace listing/mapping `.default` access with subscript access\n  }\n}","preventionTips":["Always use `[]` for Listing/Mapping element access, never `.` property syntax.","Never reference `.default` on Listing or Mapping.","Keep collection values typed as Listing/Mapping so errors are precise."],"tags":["pkl","listing","mapping","member-access"],"backgroundTag":"missing-member","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}