{"record":{"id":"b77c19c1dabe312e","repo":"apple/pkl","slug":"notasubclassoftyped-b77c19","errorCode":"notASubclassOfTyped","errorMessage":"notASubclassOfTyped","messagePattern":"notASubclassOfTyped","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/stdlib/base/MapNodes.java","lineNumber":255,"sourceCode":"    @Specialization\n    protected VmMap eval(VmMap self) {\n      return self;\n    }\n  }\n\n  public abstract static class toDynamic extends ExternalMethod0Node {\n    @Specialization\n    protected VmDynamic eval(VmMap self) {\n      return self.toDynamic();\n    }\n  }\n\n  public abstract static class toTyped extends ExternalMethod1Node {\n    @Specialization\n    @TruffleBoundary\n    protected VmTyped eval(VmMap self, VmClass clazz) {\n      if (!clazz.isSubclassOf(BaseModule.getTypedClass())) {\n        throw exceptionBuilder().evalError(\"notASubclassOfTyped\", clazz).build();\n      }\n\n      VmUtils.checkIsInstantiable(clazz, null);\n\n      var result =\n          new VmTyped(\n              VmUtils.createEmptyMaterializedFrame(),\n              clazz.getPrototype(),\n              clazz,\n              clazz.getMapToTypedMembers());\n      result.setExtraStorage(self);\n      return result;\n    }\n  }\n\n  public abstract static class toMapping extends ExternalMethod0Node {\n    @Specialization\n    protected VmMapping eval(VmMap self) {","sourceCodeStart":237,"sourceCodeEnd":273,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/stdlib/base/MapNodes.java#L237-L273","documentation":"Thrown by Map.toTyped(clazz) when the supplied class is not a subclass of the pkl.base Typed class. toTyped only converts a map into an instance of type-constrained (Typed) classes, so the library rejects any class that isn't a Typed subclass before attempting instantiation.","triggerScenarios":"Calling someMap.toTyped(SomeClass) where SomeClass is a plain open/class module class, an Amended/ Dynamic class, or any class not declared with a type constraint (i.e. not extending Typed).","commonSituations":"Passing a module class or a base type like String/Int instead of a user-defined type-constrained class, refactoring a class so it no longer has a type constraint, or confusion between toTyped and toDynamic/toMap.","solutions":["Pass a type-constrained class (one declared with a constraint, e.g. `class Person { name: String }`) to toTyped","Use Map.toDynamic instead if you just need a Dynamic object","Check with clazz.isSubclassOf(Typed) or inspect the class declaration for a type constraint","Use toTyped on a class from a .pkl module that actually extends Typed"],"exampleFix":"// before\nm.toTyped(String) // not a Typed subclass\n// after\nclass Person { name: String }\nm.toTyped(Person)","handlingStrategy":"type-guard","validationCode":"// Pkl\nif (!clazz.isSubclassOf(module(base: Typed))) { /* handle */ }","typeGuard":"function isTypedClass(clazz: Class): Boolean = clazz.isSubclassOf(Typed)","tryCatchPattern":null,"preventionTips":["Only pass type-constrained classes (declared with constraints) to toTyped","Use toDynamic when you don't need a typed instance","Check the class declaration extends/handles Typed before converting","Keep a single well-known set of typed classes for map conversion"],"tags":["pkl","map","type-constraint","stdlib"],"backgroundTag":"type-mismatch","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"}