{"record":{"id":"156d2de5e218a3af","repo":"apple/pkl","slug":"type-mismatch-value-is-not-of-type-dynamic","errorCode":null,"errorMessage":"type mismatch: value is not of type Dynamic","messagePattern":"type mismatch: value is not of type Dynamic","errorType":"exception","errorClass":"VmTypeMismatchException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java","lineNumber":677,"sourceCode":"      return other instanceof TypedTypeNode;\n    }\n\n    @Override\n    protected boolean acceptTypeNode(boolean visitTypeArguments, TypeNodeConsumer consumer) {\n      return consumer.accept(this);\n    }\n  }\n\n  public static final class DynamicTypeNode extends ObjectSlotTypeNode {\n    public DynamicTypeNode(SourceSection sourceSection) {\n      super(sourceSection);\n    }\n\n    @Override\n    protected Object executeLazily(VirtualFrame frame, Object value) {\n      if (value instanceof VmDynamic) return value;\n\n      throw typeMismatch(value, BaseModule.getDynamicClass());\n    }\n\n    @Override\n    public VmClass getVmClass() {\n      return BaseModule.getDynamicClass();\n    }\n\n    @Override\n    public Object createDefaultValue(\n        VirtualFrame frame,\n        VmLanguage language,\n        SourceSection headerSection,\n        String qualifiedName) {\n\n      return VmDynamic.empty();\n    }\n\n    @Override","sourceCodeStart":659,"sourceCodeEnd":695,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java#L659-L695","documentation":"Pkl `Dynamic` type check failure. The declared type was `Dynamic` (the type of objects built with `new Dynamic {}`), and the runtime value was not a VmDynamic — e.g. a typed class instance, Listing, Mapping, or a primitive. Note this is an exact-class check, not a subclass check: even class instances fail.","triggerScenarios":"Assigning a `new SomeClass {...}` instance, a Listing/Mapping, Int/String/Boolean, or null to a property typed `Dynamic`; passing such values to an API parameter declared `Dynamic`.","commonSituations":"Assuming `Dynamic` is a supertype of all objects (in Pkl it is a specific object kind); wrapping typed objects in configs that declare Dynamic; returning a class instance from a function typed to return Dynamic.","solutions":["Use `new Dynamic { ... }` to build the value so its runtime type is actually Dynamic.","If a typed instance is what you have, change the declared type to the concrete class or `Typed`/`Object`.","Remember Listing/Mapping are not Dynamic; declare the property as `Listing`/`Mapping` instead.","Wrap primitives directly without a Dynamic type — declare the property as the primitive type."],"exampleFix":"// before\nconf: Dynamic = new Server { host = \"localhost\" }\n// after\nconf: Dynamic = new Dynamic { host = \"localhost\" }","handlingStrategy":"type-guard","validationCode":"// Pkl\nif (value is Dynamic) {\n  conf: Dynamic = value\n}","typeGuard":"function isDynamic(value: Any): Boolean = value is Dynamic","tryCatchPattern":"// Guard with `is Dynamic`; note it is an exact-kind check — class instances fail.","preventionTips":["Do not assume Dynamic is a supertype of all objects","Use `new Dynamic { ... }` when a Dynamic-typed value is required","Prefer concrete class types over Dynamic in APIs"],"tags":["pkl","type-mismatch","dynamic","typecheck"],"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"}