{"record":{"id":"dfd1106895a7c58a","repo":"apple/pkl","slug":"invalidobjectmembermodifier","errorCode":"invalidObjectMemberModifier","errorMessage":"invalidObjectMemberModifier (dynamic errorMessage key)","messagePattern":"invalidObjectMemberModifier \\(dynamic errorMessage key\\)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java","lineNumber":2998,"sourceCode":"      var previousValue = EconomicMaps.put(members, key, value);\n      if (previousValue != null) {\n        CompilerDirectives.transferToInterpreter();\n        throw exceptionBuilder()\n            .evalError(\"duplicateDefinition\", new ProgramValue(\"\", key))\n            .withSourceSection(value.getHeaderSection())\n            .build();\n      }\n    }\n  }\n\n  private int doVisitModifiers(\n      List<? extends Modifier> modifiers, int validModifiers, String errorMessage) {\n\n    var result = VmModifier.NONE;\n    for (var ctx : modifiers) {\n      int modifier = visitModifier(ctx);\n      if ((modifier & validModifiers) == 0) {\n        throw exceptionBuilder()\n            .evalError(errorMessage, ctx.getValue().name().toLowerCase(Locale.ROOT))\n            .withSourceSection(createSourceSection(ctx))\n            .build();\n      }\n      result += modifier;\n    }\n\n    // flag modifier combinations that are never valid right away\n\n    if (VmModifier.isExternal(result) && !ModuleKeys.isStdLibModule(moduleKey)) {\n      throw exceptionBuilder()\n          .evalError(\"cannotDefineExternalMember\")\n          .withSourceSection(createSourceSection(modifiers, ModifierValue.EXTERNAL))\n          .build();\n    }\n\n    if (VmModifier.isLocal(result) && VmModifier.isHidden(result)) {\n      throw exceptionBuilder()","sourceCodeStart":2980,"sourceCodeEnd":3016,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java#L2980-L3016","documentation":"`doVisitModifiers` validates each modifier against a bitmask of modifiers valid in the current context; when a modifier (e.g. `abstract` on a property, or `hidden` on a class) is not allowed, it throws `invalidObjectMemberModifier` with the modifier name interpolated into the message (AstBuilder.java:2998).","triggerScenarios":"Using a modifier outside its allowed context, e.g. `open`/`abstract` on a non-class member, `fixed` on an object method, or any member modifier at module level where only a subset is valid.","commonSituations":"Copy-pasting modifiers between property/class declarations; misunderstanding which modifiers apply to object members vs classes; typos producing unexpected modifier placements.","solutions":["Read the interpolated modifier name in the message and remove it from that declaration.","Check Pkl docs for modifiers valid for the member kind (properties: `local`, `hidden`, `fixed`, `external`; classes: `open`, `abstract`, `open` etc.).","Move the modifier to the correct declaration site if it belongs elsewhere."],"exampleFix":"// before\nabstract foo = 1\n// after\nfoo = 1","handlingStrategy":"validation","validationCode":"// valid member modifiers per Pkl grammar: local, hidden, fixed, external, abstract\nconst VALID = new Set([\"local\", \"hidden\", \"fixed\", \"external\", \"abstract\", \"open\"]);\nconst mods = [...pklSource.matchAll(/^\\s*([a-zA-Z]+)\\s+[a-zA-Z_]\\w*/gm)].map(m => m[1]);\nmods.forEach(m => { if (!VALID.has(m)) throw new Error(`invalid modifier: ${m}`); });","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check the Pkl language reference table of valid modifiers per declaration kind.","Add one modifier at a time and re-run `pkl eval`.","Don't copy modifier lists blindly between class and property declarations."],"tags":["pkl","parser","modifier","validation"],"backgroundTag":"invalid-enum-value","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"}