{"record":{"id":"16451ffa5f040b46","repo":"apple/pkl","slug":"objectcannothaveproperty","errorCode":"objectCannotHaveProperty","errorMessage":"Object of type `{0}` cannot have a property (other than `default`).","messagePattern":"Object of type `(.+?)` cannot have a property \\(other than `default`\\)\\.","errorType":"exception","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/expression/generator/GeneratorPropertyNode.java","lineNumber":90,"sourceCode":"\n  @SuppressWarnings(\"unused\")\n  @Specialization(guards = {\"parent == getListingClass()\", \"checkIsValidListingProperty()\"})\n  protected void evalListingClass(VirtualFrame frame, VmClass parent, ObjectData data) {\n    data.addProperty(frame, member, this);\n  }\n\n  @SuppressWarnings(\"unused\")\n  @Specialization(\n      guards = {\"isTypedObjectClass(parent)\", \"checkIsValidTypedProperty(parent, member)\"})\n  protected void evalTypedObjectClass(VirtualFrame frame, VmClass parent, ObjectData data) {\n    data.addProperty(frame, member, this);\n  }\n\n  @Fallback\n  @SuppressWarnings(\"unused\")\n  void fallback(Object parent, ObjectData data) {\n    CompilerDirectives.transferToInterpreter();\n    throw exceptionBuilder()\n        .evalError(\n            \"objectCannotHaveProperty\",\n            parent instanceof VmClass ? parent : VmUtils.getClass(parent))\n        .withSourceSection(member.getHeaderSection())\n        .build();\n  }\n\n  @Idempotent\n  protected boolean checkIsValidListingProperty() {\n    if (member.isLocal() || member.getName() == Identifier.DEFAULT) return true;\n\n    CompilerDirectives.transferToInterpreter();\n    throw exceptionBuilder()\n        .evalError(\"objectCannotHaveProperty\", BaseModule.getListingClass())\n        .withSourceSection(member.getHeaderSection())\n        .build();\n  }\n","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/expression/generator/GeneratorPropertyNode.java#L72-L108","documentation":"Only `default` (and local) properties may be set on objects that aren't Dyanamic — e.g. typed class instances, List/Set/Map values, or functions. The generic fallback of GeneratorPropertyNode rejects any other property assignment with the object's type.","triggerScenarios":"Amending a typed object or non-Dynamic value with a named property (`value { foo = 1 }`) where the parent type's fallback path is hit — parent is neither Dynamic, Listing, Mapping, nor Module. Raised in the public `fallback` node.","commonSituations":"Adding properties to a List or Map amendment; trying to override a property on a typed class instance that doesn't declare it; amending a base value like Int/String as if it were an object.","solutions":["Remove the property or change it to `default` if overriding the object's default value is intended.","Mark the member `local` if it's an internal helper that must not appear on the object.","If the target should accept arbitrary properties, ensure it is a Dynamic (or the class declares the property)."],"exampleFix":"// before\nmyList { extra = 1 }\n// after\nlocal extra = 1\nmyList { ... }","handlingStrategy":"type-guard","validationCode":"// Only assign named properties to Dynamic/module objects\nif (target is Dynamic || target is Module) {\n  // named property assignment is safe\n}","typeGuard":"function acceptsProperties(v: Any): Boolean = v is Dynamic || v is Module","tryCatchPattern":null,"preventionTips":["Don't add properties to List/Set/Map or typed-class amendments.","Use `local` bindings for helpers inside any object body.","Only `default` may be overridden on non-Dynamic objects."],"tags":["pkl","property","typed-class","amendment"],"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"}