diff --git a/src/vm/wren_compiler.c b/src/vm/wren_compiler.c index 48cc5659..390c7250 100644 --- a/src/vm/wren_compiler.c +++ b/src/vm/wren_compiler.c @@ -1853,6 +1853,9 @@ static void map(Compiler* compiler, bool allowAssignment) { ignoreNewlines(compiler); + // Map with trailing comma. + if (peek(compiler) == TOKEN_RIGHT_BRACE) break; + // Push a copy of the map since the subscript call will consume it. emit(compiler, CODE_DUP); diff --git a/test/language/map/trailing_comma.wren b/test/language/map/trailing_comma.wren new file mode 100644 index 00000000..7dd0a69f --- /dev/null +++ b/test/language/map/trailing_comma.wren @@ -0,0 +1,7 @@ +var map = { + "a": 1, + "b": 2, +} + +IO.print(map["a"]) // expect: 1 +IO.print(map["b"]) // expect: 2