fix: change map key parsing precedence from PRIMARY to UNARY
In wren_compiler.c, the map() function now parses map keys with PREC_UNARY instead of PREC_PRIMARY, allowing unary operators like negation and bitwise NOT in key expressions. Added test/language/map/bad_key_precedence.wren to verify that binary operators (e.g., 1 + 2) still produce an error when used as keys, and test/language/map/precedence.wren to validate correct parsing of primary, call, and unary expressions in map keys.
This commit is contained in:
@@ -1987,7 +1987,7 @@ static void map(Compiler* compiler, bool allowAssignment)
|
||||
if (peek(compiler) == TOKEN_RIGHT_BRACE) break;
|
||||
|
||||
// The key.
|
||||
parsePrecedence(compiler, false, PREC_PRIMARY);
|
||||
parsePrecedence(compiler, false, PREC_UNARY);
|
||||
consume(compiler, TOKEN_COLON, "Expect ':' after map key.");
|
||||
ignoreNewlines(compiler);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user