apple/pkl · error · VmReferenceAccessError
cannotFindMember
Error message
cannotFindMember
What it means
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.
Source
Thrown at pkl-core/src/main/java/org/pkl/core/runtime/VmReference.java:216
@TruffleBoundary
private VmReference withAccess(
BiConsumer<PType, Set<PType>> checkCandidate, Supplier<VmTyped> makeAccess) {
Set<PType> candidates = new HashSet<>();
for (var t : iterateTypes(referentType)) {
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);
}View on GitHub (pinned to f3efcbfc9b)
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.
Example fix
// before (union type member reference) x: Int | String y = x.someProp // after x: SomeClass y = x.someProp
Defensive patterns
Strategy: type-guard
Validate before calling
// Pkl: only reference properties on concrete class types
if (x is SomeClass) { ... }
typealias ValidType = SomeClass // avoid aliasing to unions you later access by property Type guard
// Pkl function isClassTyped(x: Any): Boolean = x is SomeClass
Try / catch
try {
eval(modSrc);
} catch (EvalException e) {
if (e.getMessage().contains("cannotFindMember")) {
// check that the referenced expression resolves to a class type
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Type annotations referencing properties of union types or type aliases; referencing members of `unknown`-typed values in `amends`/typechecked contexts.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- externalMember
- defaultMember
- defaultMember/cannotFindMember
- cannotFindMember
- cannotInstantiateAbstractClass
AI-assisted analysis of apple/pkl@f3efcbfc9b (2026-09-08).
Data as JSON: /api/errors/bd06d8ec6841b21d.
Report an issue: GitHub.