{"record":{"id":"8550ac290bacb477","repo":"apple/pkl","slug":"invalidsupertype","errorCode":"invalidSupertype","errorMessage":"invalidSupertype","messagePattern":"invalidSupertype","errorType":"error_code","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java","lineNumber":1922,"sourceCode":"\n          var supertypeCtx = clazz.getSuperClass();\n\n          // needs to be inside `enterClass` so that class' type parameters are in scope\n          var supertypeNode =\n              supertypeCtx != null\n                  ? visitType(supertypeCtx)\n                  : isBaseModule && className == org.pkl.core.runtime.Identifier.ANY\n                      ? null\n                      : new UnresolvedTypeNode.Declared(\n                          VmUtils.unavailableSourceSection(),\n                          resolveBaseModuleClass(\n                              org.pkl.core.runtime.Identifier.TYPED, BaseModule::getTypedClass));\n\n          if (!(supertypeNode == null\n              || supertypeNode instanceof UnresolvedTypeNode.Declared\n              || supertypeNode instanceof UnresolvedTypeNode.Parameterized\n              || supertypeNode instanceof UnresolvedTypeNode.Module)) {\n            throw exceptionBuilder()\n                .evalError(\"invalidSupertype\", supertypeNode.getSourceSection().getCharacters())\n                .withSourceSection(supertypeNode.getSourceSection())\n                .build();\n          }\n\n          var classInfo =\n              PClassInfo.get(\n                  moduleInfo.getModuleName(),\n                  className.toString(),\n                  moduleInfo.getModuleKey().getUri());\n          var propertyNames = CollectionUtils.<String>newHashSet(properties.size());\n\n          var classNode =\n              new ClassNode(\n                  sourceSection,\n                  headerSection,\n                  createDocSourceSection(clazz.getDocComment()),\n                  annotations,","sourceCodeStart":1904,"sourceCodeEnd":1940,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/builder/AstBuilder.java#L1904-L1940","documentation":"A class or typealias supertype must be a declared, parameterized, or module type reference. If the parsed supertype node is any other UnresolvedTypeNode form (e.g. union, nullable, string-literal type), AstBuilder throws invalidSupertype with the offending source text. Pkl requires supertypes to be nominal so subtype relationships are well-defined.","triggerScenarios":"Writing `class Foo extends SomeUnionType` or `extends String?`/`extends \"x\"|Number` — any supertype expression that parses to an UnresolvedTypeNode other than Declared, Parameterized, or Module.","commonSituations":"Trying to extend a union or nullable type; using a predicate or quoted-string type as a parent class; refactoring types so a parent became a union without updating the extends clause.","solutions":["Extend a single declared class (or a parameterized one, e.g. `extends List<Int>`).","Remove the extends clause and use a type-constrained property instead.","Check the highlighted supertype text and replace the non-nominal type with the concrete class you meant."],"exampleFix":"// before\nclass Named extends String?(name) {}\n\n// after\nclass Named extends Base.Named {}","handlingStrategy":"validation","validationCode":"// Validate supertype is a plain nominal reference before writing:\nif (!supertype.matches(\"[A-Za-z_][\\\\w.]*([<].*[>])?\")) {\n  throw new IllegalArgumentException(\"supertype must be a declared/parameterized type: \" + supertype);\n}","typeGuard":"boolean isNominalTypeRef(String t) { return t != null && t.matches(\"[A-Za-z_][\\\\w.]*(<.*>)?\"); }","tryCatchPattern":null,"preventionTips":["Never use union, nullable, or predicate types after `extends`.","Ensure the parent class exists and is importable (declared/parameterized reference).","When refactoring a parent class into a union, update all extends clauses."],"tags":["pkl","ast","inheritance","type-system"],"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-14T11:17:12.474Z"}