{"record":{"id":"e6b8e05d91d6d87e","repo":"apple/pkl","slug":"objectcannothaveproperty-e6b8e0","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/literal/SpecializedObjectLiteralNode.java","lineNumber":150,"sourceCode":"        if (!(key instanceof Long)) {\n          CompilerDirectives.transferToInterpreter();\n          throw exceptionBuilder()\n              .evalError(\"wrongListingKeyType\", new ProgramValue(\"\", VmUtils.getClass(key)))\n              .withSourceSection(member.getHeaderSection())\n              .build();\n        }\n\n        long index = (long) key;\n        if (index < 0) {\n          // defer handling of negative index to checkMaxListingMemberIndex() (gives more uniform\n          // error messages)\n          maxIndex = Long.MAX_VALUE;\n          break;\n        } else if (index > maxIndex) {\n          maxIndex = index;\n        }\n      } else if (memberName != Identifier.DEFAULT) {\n        throw exceptionBuilder()\n            .evalError(\"objectCannotHaveProperty\", BaseModule.getListingClass())\n            .withSourceSection(member.getHeaderSection())\n            .build();\n      }\n    }\n\n    if (parametersDescriptor != null) {\n      throw exceptionBuilder()\n          .evalError(\"listingAmendmentCannotHaveParameters\")\n          .withSourceSection(getParentNode().getSourceSection())\n          .build();\n    }\n\n    maxListingMemberIndex = maxIndex;\n    return true;\n  }\n\n  @SuppressWarnings(\"SameReturnValue\")","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/expression/literal/SpecializedObjectLiteralNode.java#L132-L168","documentation":"A `Listing` can only contain positional elements plus an optional `default` element; it cannot carry named properties. `checkIsValidListingAmendment` throws `objectCannotHaveProperty` (parameterized with the base `Listing` class) when a Listing amendment declares a named member other than `default`.","triggerScenarios":"Adding a named property inside a Listing amendment, e.g. `items { name = \"x\" }` where `items` is a `Listing`; forgetting that within a Listing body only `[index] = ...` and `default { ... }` are legal.","commonSituations":"Mixing Mapping-style and Listing-style member syntax in one amendment; pasting property overrides into a Listing block; schema drift where a field was moved from a property to an element.","solutions":["Remove the named property from the Listing amendment","Move the property to an element: `[\"name\"]` won't work either — instead put the data into elements via `[0] = ...` or restructure the container as a `Mapping`","Use `default { ... }` if you intended to set the default element"],"exampleFix":"// before (items: Listing)\nitems { label = \"x\"; [0] = 1 }\n// after\nitems { [0] = 1 }\n","handlingStrategy":"validation","validationCode":"// In a Listing amendment, allowed members are only [i] = v and default { ... } — review body before eval.\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never mix named properties into Listing bodies","Restructure to a class-based object if named fields are needed alongside elements"],"tags":["pkl","listing","property","schema"],"backgroundTag":"schema-validation-failed","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"}