{"record":{"id":"5cdc22622550cf37","repo":"apple/pkl","slug":"unexpectedtoken-5cdc22","errorCode":"unexpectedToken","errorMessage":"Unexpected token `{0}`. Expected `{1}`.","messagePattern":"Unexpected token `(.+?)`\\. Expected `(.+?)`\\.","errorType":"exception","errorClass":"GenericParserError","httpStatus":null,"severity":"error","filePath":"pkl-parser/src/main/java/org/pkl/parser/GenericParserImpl.java","lineNumber":552,"sourceCode":"    children.add(new Node(NodeType.CLASS_METHOD_BODY, body));\n    return new Node(NodeType.OBJECT_METHOD, children);\n  }\n\n  private Node parseMemberPredicate() {\n    var children = new ArrayList<Node>();\n    children.add(makeTerminal(next()));\n    ff(children);\n    children.add(parseExpr());\n    ff(children);\n    var firstBrack = expect(Token.RBRACK, \"unexpectedToken\", \"]]\");\n    children.add(makeTerminal(firstBrack));\n    var secondbrack = expect(Token.RBRACK, \"unexpectedToken\", \"]]\");\n    children.add(makeTerminal(secondbrack));\n    if (firstBrack.span.charIndex() != secondbrack.span.charIndex() - 1) {\n      // There shouldn't be any whitespace between the first and second ']'.\n      var span = firstBrack.span.endWith(secondbrack.span);\n      var text = lexer.textFor(span.charIndex(), span.length());\n      throw parserError(ErrorMessages.create(\"unexpectedToken\", text, \"]]\"), firstBrack.span);\n    }\n    ff(children);\n    if (lookahead == Token.ASSIGN) {\n      children.add(makeTerminal(next()));\n      ff(children);\n      children.add(parseExpr(\"}\"));\n      return new Node(NodeType.MEMBER_PREDICATE, children);\n    }\n    children.addAll(parseBodyList());\n    return new Node(NodeType.MEMBER_PREDICATE, children);\n  }\n\n  private Node parseObjectEntry() {\n    var children = new ArrayList<Node>();\n    var header = new ArrayList<Node>();\n    expect(Token.LBRACK, header, \"unexpectedToken\", \"[\");\n    ff(header);\n    header.add(parseExpr());","sourceCodeStart":534,"sourceCodeEnd":570,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-parser/src/main/java/org/pkl/parser/GenericParserImpl.java#L534-L570","documentation":"A member predicate's closing brackets were malformed: after the first `]`, the expected `]]` didn't match, or there was whitespace between the two `]` characters. Pkl requires the predicate syntax `is[...]` / `[[...]]`-style double bracket to be contiguous.","triggerScenarios":"parseMemberPredicate calls expect(RBRACK, \"unexpectedToken\", \"]]\") or detects `firstBrack.charIndex != secondbrack.charIndex - 1` — e.g. writing `is[ x ] [ ]` with a space between `]` and `]`, or omitting the second bracket.","commonSituations":"Typing a space between the closing brackets of `when (cond) { ... }`-style member predicates; hand-writing predicate syntax copied loosely from docs; editor auto-spacing between brackets.","solutions":["Write the double closing bracket with no whitespace: `]]`","Ensure the predicate opening used `[[` and closing `]]` in matching pairs","Let a Pkl-aware formatter normalize the predicate syntax"],"exampleFix":"// before\nx is[ Int ] ]\n// after\nx is[Int]","handlingStrategy":"validation","validationCode":"/\\]\\s*\\]/.test(src) === false // reject whitespace between predicate closing brackets","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never type a space between the two closing brackets of a member predicate","Copy predicate syntax verbatim from docs","Enable a formatter that normalizes `]]`"],"tags":["parser","pkl","syntax-error","unexpected-token","whitespace"],"backgroundTag":"invalid-argument-format","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"}