{"record":{"id":"b6492b2d560bc140","repo":"apple/pkl","slug":"type-mismatch-value-is-not-the-expected-string-li","errorCode":null,"errorMessage":"type mismatch: value is not the expected string literal","messagePattern":"type mismatch: value is not the expected string literal","errorType":"exception","errorClass":"VmTypeMismatchException","httpStatus":null,"severity":"error","filePath":"pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java","lineNumber":611,"sourceCode":"    }\n\n    public String getLiteral() {\n      return literal;\n    }\n\n    @Override\n    public boolean doIsEquivalentTo(TypeNode other) {\n      if (!(other instanceof StringLiteralTypeNode stringLiteralTypeNode)) {\n        return false;\n      }\n      return literal.equals(stringLiteralTypeNode.literal);\n    }\n\n    @Override\n    protected Object executeLazily(VirtualFrame frame, Object value) {\n      if (literal.equals(value)) return value;\n\n      throw typeMismatch(value, literal);\n    }\n\n    @Override\n    public Object createDefaultValue(\n        VirtualFrame frame,\n        VmLanguage language,\n        SourceSection headerSection,\n        String qualifiedName) {\n\n      return literal;\n    }\n\n    @Override\n    public VmTyped getMirror() {\n      return MirrorFactories.stringLiteralTypeFactory.create(this);\n    }\n\n    @Override","sourceCodeStart":593,"sourceCodeEnd":629,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-core/src/main/java/org/pkl/core/ast/type/TypeNode.java#L593-L629","documentation":"Pkl string literal type check failure (StringLiteralTypeNode.executeLazily). A property or argument was declared with a string literal type such as `\"red\"|...` or a single `\"literal\"` type, and the runtime value did not exactly equal that literal. Pkl treats string literals as first-class types, so equality is strict and type-checked at evaluation time.","triggerScenarios":"Assigning any string (or non-string) whose exact contents differ from the declared literal type, e.g. `mode: \"produc\"` where the type is `\"production\"`; case or whitespace differences also fail.","commonSituations":"Typos in enum-like string configuration, trailing whitespace or quotes pasted from docs, casing differences (`\"Prod\"` vs `\"prod\"`), or supplying a variable/interpolated string where a literal type is required.","solutions":["Compare the value character-by-character with the expected literal in the error/type position; fix the typo or casing.","If multiple values are valid, widen the declared type to a union of string literals (`\"a\" | \"b\"`) or to `String`.","Trim/normalize the input value before assignment.","Use an enum-like listing or type alias so all valid literals are visible in one place."],"exampleFix":"// before\nlevel: \"debug\" = \"Debug\"\n// after\nlevel: \"debug\" = \"debug\"   // exact literal match required","handlingStrategy":"validation","validationCode":"// Pkl\nexpected: String = \"production\"\nif (value != expected) throw(\"expected literal \\\"production\\\", got: \\(value)\")","typeGuard":"function isProd(value: Any): Boolean = value is String && value == \"production\"","tryCatchPattern":"// Validate literal equality before use; in embedders catch PklException with 'type mismatch: value is not the expected string literal'.","preventionTips":["Copy literals from the type declaration, never retype them","Use type aliases to keep literal definitions in one place","Trim and lowercase external input before assigning to literal-typed fields"],"tags":["pkl","type-mismatch","string-literal","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"}