{"record":{"id":"1aef57dfa60b94b6","repo":"apple/pkl","slug":"cannotfindpropertyinobject","errorCode":"cannotFindPropertyInObject","errorMessage":"Cannot find property `{0}` in object of type `{1}`.","messagePattern":"Cannot find property `(.+?)` in object of type `(.+?)`\\.","errorType":"exception","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/expression/literal/SpecializedObjectLiteralNode.java","lineNumber":81,"sourceCode":"  protected final UnmodifiableEconomicMap<Object, ObjectMember> members;\n\n  @CompilationFinal protected long maxListingMemberIndex = Long.MIN_VALUE;\n  @CompilationFinal private boolean checkedIsValidMappingAmendment;\n\n  // only runs once per VmClass (which often means once per PropertiesLiteralNode)\n  // unless an XYZUncached specialization is active\n  @TruffleBoundary\n  @Idempotent\n  protected boolean checkIsValidTypedAmendment(Object parent) {\n    var parentClass = parent instanceof VmClass vmClass ? vmClass : VmUtils.getClass(parent);\n    VmUtils.checkIsInstantiable(parentClass, getParentNode());\n\n    for (var member : EconomicMaps.getValues(members)) {\n      if (member.isLocal()) continue;\n\n      var memberName = member.getName();\n      if (!parentClass.hasProperty(memberName)) {\n        throw exceptionBuilder()\n            .cannotFindProperty(parentClass.getPrototype(), memberName, false, false)\n            .withSourceSection(member.getHeaderSection())\n            .build();\n      }\n      var classProperty = parentClass.getProperty(memberName);\n      if (classProperty != null && classProperty.isConstOrFixed()) {\n        // tailor error message based on whether an amends declaration is used or not\n        // (i.e. `friends {}` vs. `friends = new {}`)\n        // an amends declaration's body section includes the header section, whereas normal property\n        // assignment's body section is the section after the equal sign.\n        var isAmendsDeclaration =\n            member.getHeaderSection().getCharIndex() == member.getBodySection().getCharIndex();\n        var errMsg = isAmendsDeclaration ? \"cannotAmendFixedProperty\" : \"cannotAssignFixedProperty\";\n        if (classProperty.isConst()) {\n          errMsg = isAmendsDeclaration ? \"cannotAmendConstProperty\" : \"cannotAssignConstProperty\";\n        }\n        throw exceptionBuilder()\n            .evalError(errMsg, memberName)","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/expression/literal/SpecializedObjectLiteralNode.java#L63-L99","documentation":"In a typed object amendment (`amends SomeClass`), every member must correspond to a property that exists on the parent class. `checkIsValidTypedAmendment` walks the literal's members and throws `cannotFindProperty` when a member name is not a declared property of the class being amended (and is not local).","triggerScenarios":"Writing `obj { ... amends MyClass }` with a member `foo = 1` where `MyClass` has no property `foo`; misspelling a property name; amending a class whose property was removed/renamed in a newer version of the module.","commonSituations":"Typo in property name when overriding defaults; upstream package updated and renamed a property; assuming `amends` behaves like object spread and can add new properties (it cannot for typed objects).","solutions":["Correct the member name to match an existing property of the amended class","Remove the member if it does not belong to the parent type (use a plain `new` object or extension instead if you need to add properties)","Regenerate/check the parent module's property list (`pkl eval` with docs, or read the class definition) to confirm the exact name"],"exampleFix":"// before\nserver { amends ServerConfig }\nserver { prot = 8080 } // typo\n// after\nserver { port = 8080 } // matches ServerConfig.port\n","handlingStrategy":"validation","validationCode":"// Before amending MyClass, confirm the property exists:\n// pkl eval -y 'import \"pkg.pkl\"; (pkg.MyClass).toMap().keys'\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Copy property names from the class definition or generated docs, not memory","Pin/lock dependency versions so property renames don't slip in","Remember: `amends` cannot introduce new properties on typed objects — use `new` + extension for additions"],"tags":["pkl","amends","typed-object","property-not-found"],"backgroundTag":"entity-not-found","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"}