{"record":{"id":"4508075d3cab3292","repo":"apple/pkl","slug":"cannotextendfinalmodule","errorCode":"cannotExtendFinalModule","errorMessage":"cannotExtendFinalModule","messagePattern":"cannotExtendFinalModule","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/member/ClassNode.java","lineNumber":182,"sourceCode":"    }\n  }\n\n  private void checkSupertype(TypeNode supertypeNode, @Nullable VmClass superclass) {\n    if (superclass == null) {\n      throw exceptionBuilder()\n          .evalError(\"invalidSupertype\", supertypeNode.getSourceSection().getCharacters())\n          .withSourceSection(supertypeNode.getSourceSection())\n          .build();\n    }\n    if (moduleInfo != null) {\n      if (cachedClass == superclass) {\n        throw exceptionBuilder()\n            .evalError(\"moduleCannotExtendSelf\", moduleInfo.getModuleName())\n            .withSourceSection(supertypeNode.getSourceSection())\n            .build();\n      }\n      if (superclass.isClosed()) {\n        throw exceptionBuilder()\n            .evalError(\"cannotExtendFinalModule\", superclass.getModuleName())\n            .withSourceSection(supertypeNode.getSourceSection())\n            .build();\n      }\n    } else {\n      if (cachedClass == superclass) {\n        throw exceptionBuilder()\n            .evalError(\"classCannotExtendSelf\", superclass.getDisplayName())\n            .withSourceSection(supertypeNode.getSourceSection())\n            .build();\n      }\n      if (superclass.isClosed()) {\n        throw exceptionBuilder()\n            .evalError(\"cannotExtendFinalClass\", superclass.getDisplayName())\n            .withSourceSection(supertypeNode.getSourceSection())\n            .build();\n      }\n      if (superclass.isExternal() && !classInfo.isStandardLibraryClass()) {","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/member/ClassNode.java#L164-L200","documentation":"Pkl throws cannotExtendFinalModule when a class or module tries to extend a module that is 'closed' (declared final, e.g. via an open/closed module annotation or being a sealed standard-library module). ClassNode.checkSupertype rejects inheritance from a closed superclass because closed modules promise no further subclassing. The error names the module being illegally extended.","triggerScenarios":"Writing `extends` with a superclass whose module is annotated final/closed (isClosed() returns true) and the enclosing node is a module; extending a closed standard-library module.","commonSituations":"Trying to customize behavior by inheriting from a closed library module; upgrading Pkl where a previously open module became closed; attempting to extend built-in modules such as pkl base modules that prohibit extension.","solutions":["Stop extending the closed module; instead import it and compose (use its properties/defaults) rather than inherit.","Copy the needed defaults into your own module if extension is essential.","If you own the superclass module, mark it `open` to permit subclassing.","Check the superclass module's documentation for the sanctioned customization mechanism."],"exampleFix":"// before\nmodule my_server\nextends \"@server/ClosedModule.pkl\"  // closed module\n\n// after\nmodule my_server\nimport \"@server/ClosedModule.pkl\"\nserver = new ClosedModule { /* overrides via object literal if allowed */ }","handlingStrategy":"validation","validationCode":"// Before extending a library module, confirm it is open:\n// the module file must be declared `open module ...` (absence means closed/final).\n// pkl eval my_module.pkl  -> cannotExtendFinalModule surfaces at definition","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check for `open` on a module before writing `extends` against it.","Prefer composition (import + amend object literals) over extending library modules.","Pin library versions and read changelogs for modules becoming closed.","Never attempt to extend standard-library modules."],"tags":["pkl","inheritance","final-module","module"],"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"}