{"record":{"id":"b4eb8bd0e79adaee","repo":"apple/pkl","slug":"objectcannothaveentry-b4eb8b","errorCode":"objectCannotHaveEntry","errorMessage":"Object of type `{0}` cannot have an entry.","messagePattern":"Object of type `(.+?)` cannot have an entry\\.","errorType":"error_code","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/expression/literal/SpecializedObjectLiteralNode.java","lineNumber":307,"sourceCode":"    var parentIsClass = parent instanceof VmClass;\n    var parentClass = parentIsClass ? (VmClass) parent : VmUtils.getClass(parent);\n    VmUtils.checkIsInstantiable(parentClass, getParentNode());\n\n    var property = findFirstNonDefaultProperty(members);\n    if (property != null\n        && (parentClass == BaseModule.getListingClass()\n            || parentClass == BaseModule.getMappingClass())) {\n      throw exceptionBuilder()\n          .evalError(\"objectCannotHaveProperty\", parentClass)\n          .withSourceSection(property.getHeaderSection())\n          .build();\n    }\n\n    assert firstElemOrEntry != null;\n\n    if (isTypedObjectClass(parentClass)\n        || (isElementsOnly && parentClass == BaseModule.getMappingClass())) {\n      throw exceptionBuilder()\n          .evalError(\n              isElementsOnly ? \"objectCannotHaveElement\" : \"objectCannotHaveEntry\", parentClass)\n          .withSourceSection(firstElemOrEntry.getHeaderSection())\n          .build();\n    }\n\n    throw exceptionBuilder().unreachableCode().build();\n  }\n}\n","sourceCodeStart":289,"sourceCodeEnd":317,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/expression/literal/SpecializedObjectLiteralNode.java#L289-L317","documentation":"Pkl throws `objectCannotHaveEntry` when an entry (`[key] = value`) appears in an object that cannot hold entries. In elementsEntriesFallback, a typed object class parent, or a Mapping when the literal is elements-only (no entries found and isElementsOnly), triggers this error instead of the element variant.","triggerScenarios":"Writing `[\"key\"] = value` inside a literal whose parent is a typed object class, or a literal detected as elements-only where entries are disallowed by the parent type.","commonSituations":"Adding key/value entries to an object declared with a class type; migrating a Dynamic to a typed class without converting entries to properties.","solutions":["Remove the entry from the typed object literal.","Convert the entry to a named property (`key = value`) if the class declares it.","Change the parent type to Mapping/Dynamic if key-value members are required."],"exampleFix":"// before\nnew Server { // typed class\n  [\"port\"] = 8080 // entry not allowed\n}\n// after\nnew Server {\n  port = 8080\n}","handlingStrategy":"type-guard","validationCode":"// Pkl\nif (value is TypedObject) {\n  throw \"entries are not allowed on typed objects; use properties\"\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Translate Dynamic-style `[key] = value` members to named properties when introducing a class type.","Use Mapping only when key-value members are genuinely required.","Run pkl eval/tests to catch shape mismatches early."],"tags":["pkl","typed-object","entry","object-shape"],"backgroundTag":"invalid-argument-value","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}