{"record":{"id":"029779ac945317df","repo":"apple/pkl","slug":"cannotdefineexternalmember","errorCode":"cannotDefineExternalMember","errorMessage":"cannotDefineExternalMember","messagePattern":"cannotDefineExternalMember","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java","lineNumber":3009,"sourceCode":"  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()\n          .evalError(\"redundantHiddenModifier\")\n          .withSourceSection(createSourceSection(modifiers, ModifierValue.HIDDEN))\n          .build();\n    }\n\n    if (VmModifier.isLocal(result) && VmModifier.isFixed(result)) {\n      throw exceptionBuilder()\n          .evalError(\"redundantFixedModifier\")\n          .withSourceSection(createSourceSection(modifiers, ModifierValue.FIXED))\n          .build();\n    }","sourceCodeStart":2991,"sourceCodeEnd":3027,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java#L2991-L3027","documentation":"Pkl throws `cannotDefineExternalMember` when a member is declared `external` in a module that is not a standard library module. `external` members are reserved for the built-in `pkl.*` stdlib whose implementations live in native runtime code; user modules cannot provide external members (AstBuilder.java:3009).","triggerScenarios":"Declaring `external foo: String` or `external function f()` in a user-defined module whose key is not in ModuleKeys stdlib set.","commonSituations":"Mimicking stdlib declarations when writing custom modules; copying declarations out of pkl-base source into user code; trying to stub native functions.","solutions":["Remove the `external` modifier and provide a concrete implementation.","If declaring an interface-like contract, use `abstract` in a class instead.","If extending stdlib behavior, define a normal function/property rather than an external member."],"exampleFix":"// before\nexternal function hash(input: String): String\n// after\nfunction hash(input: String): String = \"todo\"","handlingStrategy":"validation","validationCode":"if (/^\\s*external\\b/m.test(pklSource) && !isStdLibModule(moduleName)) {\n  throw new Error(\"external members are reserved for pkl.* standard library modules\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never declare `external` in application modules — it is stdlib-only.","Use `abstract` (in classes) or a `throw`-ing default body for stubs.","When reading stdlib source, don't copy `external` declarations into user code."],"tags":["pkl","parser","external","stdlib"],"backgroundTag":"unsupported-operation","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"}