{"record":{"id":"bd06d8ec6841b21d","repo":"apple/pkl","slug":"cannotfindmember","errorCode":null,"errorMessage":"cannotFindMember","messagePattern":"cannotFindMember","errorType":"error_code","errorClass":"VmReferenceAccessError","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/runtime/VmReference.java","lineNumber":216,"sourceCode":"  @TruffleBoundary\n  private VmReference withAccess(\n      BiConsumer<PType, Set<PType>> checkCandidate, Supplier<VmTyped> makeAccess) {\n    Set<PType> candidates = new HashSet<>();\n    for (var t : iterateTypes(referentType)) {\n      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    }","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/runtime/VmReference.java#L198-L234","documentation":"A reference-validation access error raised while resolving the property type for a `Reference` type-checking access: the accessed type is not a class type (e.g. an unknown/union/alias type), so its properties cannot be referenced at all. Pkl only allows property references on class types.","triggerScenarios":"Using property access/type-reference machinery (`withPropertyAccess`) against a value whose static type is not a PType.Class, e.g. referencing a property on an aliased union or a non-class type.","commonSituations":"Type annotations referencing properties of union types or type aliases; referencing members of `unknown`-typed values in `amends`/typechecked contexts.","solutions":["Narrow the expression to a concrete class type before referencing its properties.","Fix the type annotation so it names a class, not a union/alias.","Check for typos in the type reference; the resolved type may be falling back to non-class.","Use `is`/type tests or restructure so the referenced property lives on a class."],"exampleFix":"// before (union type member reference)\nx: Int | String\ny = x.someProp\n// after\nx: SomeClass\ny = x.someProp","handlingStrategy":"type-guard","validationCode":"// Pkl: only reference properties on concrete class types\nif (x is SomeClass) { ... }\ntypealias ValidType = SomeClass // avoid aliasing to unions you later access by property","typeGuard":"// Pkl\nfunction isClassTyped(x: Any): Boolean = x is SomeClass","tryCatchPattern":"try {\n  eval(modSrc);\n} catch (EvalException e) {\n  if (e.getMessage().contains(\"cannotFindMember\")) {\n    // check that the referenced expression resolves to a class type\n  }\n}","preventionTips":["Annotate values with concrete class types, not unions or bare aliases.","Avoid property references through union types.","Run `pkl eval` early in CI to catch reference errors before runtime consumers."],"tags":["pkl","type-system","reference","member-access"],"backgroundTag":"type-mismatch","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"}