{"record":{"id":"4823387d804e47af","repo":"apple/pkl","slug":"unexpectedtokenfortype","errorCode":"unexpectedTokenForType","errorMessage":"Unexpected token `)`. Expected a type.","messagePattern":"Unexpected token `\\)`\\. Expected a type\\.","errorType":"error_code","errorClass":"ParserError","httpStatus":null,"severity":"error","filePath":"pkl-parser/src/main/java/org/pkl/parser/ParserImpl.java","lineNumber":1412,"sourceCode":"      case THIS -> typ = new Type.ThisType(next().span);\n      case LPAREN -> {\n        var tk = next();\n        var children = new ArrayList<Node>();\n        Span end;\n        if (lookahead == Token.RPAREN) {\n          end = next().span;\n        } else {\n          children.addAll(parseListOf(Token.COMMA, Token.RPAREN, () -> parseType(\")\")));\n          end = expect(Token.RPAREN, \"unexpectedToken2\", \",\", \")\").span;\n        }\n        if (lookahead == Token.ARROW || children.size() > 1) {\n          expect(Token.ARROW, \"unexpectedToken\", \"->\");\n          var ret = parseType(expectation);\n          children.add(ret);\n          typ = new Type.FunctionType(children, tk.span.endWith(ret.span()));\n        } else {\n          if (children.isEmpty()) {\n            throw new ParserError(ErrorMessages.create(\"unexpectedTokenForType\", \")\"), end);\n          }\n          typ = new ParenthesizedType((Type) children.get(0), tk.span.endWith(end));\n        }\n      }\n      case IDENTIFIER -> {\n        var start = spanLookahead;\n        var name = parseQualifiedIdentifier();\n        var end = name.span();\n        TypeArgumentList typeArgumentList = null;\n        if (lookahead == Token.LT) {\n          typeArgumentList = parseTypeArgumentList();\n          end = typeArgumentList.span();\n        }\n        typ = new DeclaredType(name, typeArgumentList, start.endWith(end));\n      }\n      case STRING_START -> {\n        var str = parseStringConstant();\n        typ = new StringConstantType(str, str.span());","sourceCodeStart":1394,"sourceCodeEnd":1430,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-parser/src/main/java/org/pkl/parser/ParserImpl.java#L1394-L1430","documentation":"While parsing a parenthesized type expression, the parser hit the closing `)` as the first token inside the parentheses, meaning no type was found where one was required. It throws unexpectedTokenForType with `)` as the offending token when the child-type list is empty; if types had been parsed, the same `)` would simply close a ParenthesizedType.","triggerScenarios":"Parsing source containing an empty type parenthesis, e.g. `foo: ()` in a type position, `List<()>`, or a function type written as `() -> String` being parsed in a context where the parser does not accept the zero-argument parameter list form (the `)` arrives with no children collected yet).","commonSituations":"Writing a zero-argument function type `() -> String` against an older parser that expects at least one parameter type; typos like `Map<,>` or `()` placeholders left in unfinished code.","solutions":["Remove the empty `()` if no type was intended","For zero-argument function types, check the Pkl version — upgrade the parser/amplifier to one supporting `() -> T`, or use a placeholder parameter type if unsupported","Complete the type expression inside the parentheses, e.g. `foo: (String)` or `(String) -> Int`"],"exampleFix":"// before\nf: () -> String\n// after (if empty param lists unsupported)\nf: (nothing) -> String  // or upgrade to a parser supporting () -> T","handlingStrategy":"try-catch","validationCode":"function checkEmptyTypeParens(src) {\n  return !/\\(\\s*\\)/.test(src.replace(/\"(?:\\\\.|[^\"])*\"/g, '')); // ignore string literals\n}\n// reject empty '()' in type positions before invoking the parser (unless targeting a parser that supports () -> T)","typeGuard":"null","tryCatchPattern":"try {\n  const result = parser.parseType(source);\n} catch (e) {\n  if (e.errorId === 'unexpectedTokenForType') {\n    // fill in the missing type inside the parentheses or upgrade the parser\n  } else { throw e; }\n}","preventionTips":["Never leave `()` placeholders in type annotations","Check parser/version support for zero-argument function types `() -> T`","Use IDE completion for type syntax to avoid empty parens"],"tags":["parser","pkl","unexpected-token","type-syntax"],"backgroundTag":"unexpected-token-parse-error","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"}