{"record":{"id":"f813a567c45796e5","repo":"apple/pkl","slug":"unexpected-character-0-did-you-mean-1","errorCode":null,"errorMessage":"Unexpected character `{0}`. Did you mean `{1}`?","messagePattern":"Unexpected character `(.+?)`\\. Did you mean `(.+?)`\\?","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkl-parser/src/main/java/org/pkl/parser/Lexer.java","lineNumber":197,"sourceCode":"          nextChar();\n          yield Token.NOT_EQUAL;\n        } else yield Token.NOT;\n      }\n      case '?' -> {\n        if (lookahead == '.') {\n          nextChar();\n          yield Token.QDOT;\n        } else if (lookahead == '?') {\n          nextChar();\n          yield Token.COALESCE;\n        } else yield Token.QUESTION;\n      }\n      case '&' -> {\n        if (lookahead == '&') {\n          nextChar();\n          yield Token.AND;\n        } else {\n          throw unexpectedChar(ch, \"&&\");\n        }\n      }\n      case '|' -> {\n        if (lookahead == '>') {\n          nextChar();\n          yield Token.PIPE;\n        } else if (lookahead == '|') {\n          nextChar();\n          yield Token.OR;\n        } else {\n          yield Token.UNION;\n        }\n      }\n      case '*' -> {\n        if (lookahead == '*') {\n          nextChar();\n          yield Token.POW;\n        } else yield Token.STAR;","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-parser/src/main/java/org/pkl/parser/Lexer.java#L179-L215","documentation":"The lexer's nextDefault() sees a lone `&` character, which is not a valid Pkl token by itself. Pkl only defines the `&&` logical-and operator, so the lexer suggests `&&` via unexpectedChar(). This is a lexical scan error raised before any parsing occurs.","triggerScenarios":"Writing a single `&` in Pkl source — e.g. a bitwise-and habit from other languages, a typo writing `&&` as `&`, or an ampersand inside code that wasn't quoted or commented.","commonSituations":"Translating Java/C/TypeScript expressions to Pkl; shell scripts or YAML with unescaped `&` pasted into Pkl; template escaping mistakes.","solutions":["Replace `&` with `&&` if a logical-and was intended.","Remove the stray `&` if it is a typo.","Move the character into a string literal or comment if it was meant as data."],"exampleFix":"// before\nif (a & b) ...\n\n// after\nif (a && b) ...","handlingStrategy":"validation","validationCode":"function assertNoSingleAmpersand(src) {\n  const bad = src.replace(/&&/g, \"\").match(/&/);\n  if (bad) throw new Error(`Lone '&' at index ${bad.index}; use '&&'`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember Pkl has no bitwise `&`; only `&&` exists.","Quote any content containing ampersands as string literals.","Sanitize pasted code from C-family languages before embedding in Pkl."],"tags":["lexer","syntax-error","unexpected-character"],"backgroundTag":"invalid-characters","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"}