{"record":{"id":"643283837dd2ef87","repo":"apple/pkl","slug":"unexpectedtokenfortype-643283","errorCode":"unexpectedTokenForType","errorMessage":"Unexpected token `{0}`. Expected a type.","messagePattern":"Unexpected token `(.+?)`\\. Expected a type\\.","errorType":"exception","errorClass":"GenericParserError","httpStatus":null,"severity":"error","filePath":"pkl-parser/src/main/java/org/pkl/parser/GenericParserImpl.java","lineNumber":1220,"sourceCode":"            }\n          }\n          case IDENTIFIER -> {\n            var children = new ArrayList<Node>();\n            children.add(parseQualifiedIdentifier());\n            if (lookahead() == Token.LT) {\n              ff(children);\n              children.add(parseTypeArgumentList());\n            }\n            yield new Node(NodeType.DECLARED_TYPE, children);\n          }\n          case STRING_START ->\n              new Node(NodeType.STRING_CONSTANT_TYPE, List.of(parseStringConstant()));\n          default -> {\n            var text = _lookahead.text(lexer);\n            if (expectation != null) {\n              throw parserError(\"unexpectedTokenForType2\", text, expectation);\n            }\n            throw parserError(\"unexpectedTokenForType\", text);\n          }\n        };\n\n    if (typ.type == NodeType.FUNCTION_TYPE) return typ;\n    return parseTypeEnd(typ);\n  }\n\n  private Node parseTypeEnd(Node type) {\n    var children = new ArrayList<Node>();\n    children.add(type);\n    // nullable types\n    if (lookahead() == Token.QUESTION) {\n      ff(children);\n      children.add(makeTerminal(next()));\n      var res = new Node(NodeType.NULLABLE_TYPE, children);\n      return parseTypeEnd(res);\n    }\n    // constrained types: have to start in the same line as the type","sourceCodeStart":1202,"sourceCodeEnd":1238,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-parser/src/main/java/org/pkl/parser/GenericParserImpl.java#L1202-L1238","documentation":"The expectation-less variant thrown by parseType's default branch: a token that cannot start a type was found, and no expectation hint is available. The message includes the offending token text and simply states a type was expected.","triggerScenarios":"A type annotation, extends clause, type alias, or type constraint position contains a non-type token — e.g. `x: 5`, `foo: ->`, or an operator/keyword in type position where parseType was called without an expectation.","commonSituations":"Typos in type names; using value syntax instead of type syntax in annotations; generated .pkl emitting placeholders like `???` in type slots; editors auto-completing wrong tokens.","solutions":["Replace the token with a valid type (e.g. String, Int, MyClass, `module`, or a union).","Check for typos in the type name or stray characters in the annotation.","Verify the type is declared/imported if a custom type was intended.","Wrap constant string types in quotes if a literal-typed value was meant, e.g. `\"prod\"`."],"exampleFix":"// before\nport: 8\n\n// after\nport: Int","handlingStrategy":"validation","validationCode":"// Type annotation slots must start with a type-starting token\nfunction typeAnnotationWellFormed(src) {\n  return !/:\\s*(?![A-Za-z_\\\"(])[\\s\\S]/.test(src);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify custom types are declared or imported before use in annotations.","Use type aliases for complex types instead of inlining error-prone expressions.","Check generated .pkl for placeholder tokens left in type positions."],"tags":["pkl","parser","syntax-error","type-annotation"],"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-17T15:17:12.973Z"}