{"record":{"id":"fd3b7a1753057907","repo":"apple/pkl","slug":"notasubclassoftyped","errorCode":"notASubclassOfTyped","errorMessage":"notASubclassOfTyped","messagePattern":"notASubclassOfTyped","errorType":"error_code","errorClass":"VmException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/stdlib/base/DynamicNodes.java","lineNumber":101,"sourceCode":"    protected VmList eval(VmDynamic self) {\n      var builder = VmList.EMPTY.builder();\n      self.forceAndIterateMemberValues( // could be smarter and only force elements\n          (key, member, value) -> {\n            if (member.isElement()) {\n              builder.add(value);\n            }\n            return true;\n          });\n      return builder.build();\n    }\n  }\n\n  public abstract static class toTyped extends ExternalMethod1Node {\n    @Specialization\n    protected VmObjectLike eval(VmDynamic self, VmClass clazz) {\n      if (!clazz.isSubclassOf(BaseModule.getTypedClass())) {\n        CompilerDirectives.transferToInterpreter();\n        throw exceptionBuilder().evalError(\"notASubclassOfTyped\", clazz).build();\n      }\n\n      VmUtils.checkIsInstantiable(clazz, this);\n\n      var result =\n          new VmTyped(\n              VmUtils.createEmptyMaterializedFrame(),\n              clazz.getPrototype(),\n              clazz,\n              clazz.getDynamicToTypedMembers());\n      result.setExtraStorage(self);\n      return result;\n    }\n  }\n}\n","sourceCodeStart":83,"sourceCodeEnd":117,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/stdlib/base/DynamicNodes.java#L83-L117","documentation":"DynamicNodes' `toTyped` method converts a Dynamic object into an instance of a given Pkl class. The argument must be a class that is a subclass of `Typed` (the base of all typed object classes); otherwise it throws `notASubclassOfTyped`. Classes like Module, List, Map or user classes not extending Typed cannot be used as conversion targets.","triggerScenarios":"Calling `dynamic.toTyped(SomeClass)` (DynamicNodes.java:101) where SomeClass is a Pkl class not derived from `Typed` — e.g. passing `Int`, `Listing`, `Module`, or an annotation/interface-like class.","commonSituations":"Mixing up class references when converting dynamic config (passing a module class instead of a typed class), refactoring that replaced a typed class with an untyped base, or generic helper code that accepts any `Class` value.","solutions":["Pass a class declared with properties (a typed class) that implicitly subclasses `Typed`, e.g. `dynamic.toTyped(MyConfig)`.","Verify the argument is a class value (lowercase `Class` reference, not an instance or module).","If the target is a module, use module-appropriate conversion instead of `toTyped`.","Check that the class was not refactored into a non-Typed base class."],"exampleFix":"// before\ntyped = dynamic.toTyped(Listing)  // Listing is not a subclass of Typed\n// after\ntyped = dynamic.toTyped(MyConfigClass)  // a typed class","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Pkl: only call toTyped with typed classes\nfunction canToTyped(clazz) = clazz.isSubclassOf(Typed)","tryCatchPattern":null,"preventionTips":["Only pass classes that declare typed properties","Don't pass modules, Listings, or primitive classes to toTyped","Verify class references after refactors"],"tags":["pkl","dynamic","typed","type-mismatch"],"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"}