{"record":{"id":"adbdc0ccdaf1bda4","repo":"apple/pkl","slug":"unexpectedcurlyprobablyamendsexpression","errorCode":"unexpectedCurlyProbablyAmendsExpression","errorMessage":"Unexpected token: `'{'`. If you meant to write an amends expression, wrap the parent in parentheses. Try: `({0}) '{' ... '}'`","messagePattern":"Unexpected token: `'(.+?)\\) '(.+?)'`","errorType":"exception","errorClass":"GenericParserError","httpStatus":null,"severity":"error","filePath":"pkl-parser/src/main/java/org/pkl/parser/GenericParserImpl.java","lineNumber":927,"sourceCode":"          }\n        };\n    return parseExprRest(expr);\n  }\n\n  @SuppressWarnings(\"DuplicatedCode\")\n  private Node parseExprRest(Node expr) {\n    // amends\n    if (lookahead() == Token.LBRACE) {\n      var children = new ArrayList<Node>();\n      children.add(expr);\n      ff(children);\n      if (expr.type == NodeType.PARENTHESIZED_EXPR\n          || expr.type == NodeType.AMENDS_EXPR\n          || expr.type == NodeType.NEW_EXPR) {\n        children.add(parseObjectBody());\n        return parseExprRest(new Node(NodeType.AMENDS_EXPR, children));\n      }\n      throw parserError(\"unexpectedCurlyProbablyAmendsExpression\", expr.text(lexer.getSource()));\n    }\n    return expr;\n  }\n\n  private boolean isFunctionLiteral() {\n    var originalCursor = cursor;\n    try {\n      next(); // open (\n      ff();\n      var token = next().token;\n      ff();\n      if (token == Token.RPAREN) {\n        return lookahead == Token.ARROW;\n      }\n      if (token == Token.UNDERSCORE) {\n        return true;\n      }\n      if (token != Token.IDENTIFIER) {","sourceCodeStart":909,"sourceCodeEnd":945,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-parser/src/main/java/org/pkl/parser/GenericParserImpl.java#L909-L945","documentation":"A `{` appeared where an expression result cannot be amended: the parsed expression was not parenthesized, an amends, or a new expression. Pkl suggests wrapping the base expression in parentheses if an amends was intended, since `foo{...}` is otherwise ambiguous/invalid.","triggerScenarios":"parseExprRest sees Token.LBRACE after an expression whose node type is none of PARENTHESIZED_EXPR, AMENDS_EXPR, NEW_EXPR — e.g. `x.y * 2 { ... }` or a plain identifier from a non-amendable parse path.","commonSituations":"Trying to amend a function call or computed value without parentheses; intending object-literal syntax from another language (JSON/JS) where `{}` follows any expression; forgetting `new` before an object body.","solutions":["Wrap the base expression in parentheses: `(expr) { ... }`","Use `new` for fresh objects: `new { ... }` instead of `expr { ... }`","Remove the `{ ... }` block if no amends was intended"],"exampleFix":"// before\nlet (x = base) x { port = 1 }\n// after\n(base) { port = 1 }\n// or\nnew { port = 1 }","handlingStrategy":"validation","validationCode":"/[^\\s)\\]]\\s*\\{/.test(src) // suspicious '{' directly after a non-parenthesized expression — prefer '(expr) {' or 'new {'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always wrap computed base expressions in parentheses before amending","Use `new { ... }` for fresh objects","Don't copy JS/JSON object-literal patterns into Pkl expressions"],"tags":["parser","pkl","syntax-error","amends","curly-braces"],"backgroundTag":"unexpected-token","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"}