From b20c9a1b387b6fccef2fcd8fa93306cde1b96c8c Mon Sep 17 00:00:00 2001 From: Lukas Werling Date: Sat, 30 May 2015 22:18:37 +0200 Subject: [PATCH] Allow trailing comma in list literal --- src/vm/wren_compiler.c | 3 +++ test/language/list/trailing_comma.wren | 7 +++++++ 2 files changed, 10 insertions(+) create mode 100644 test/language/list/trailing_comma.wren diff --git a/src/vm/wren_compiler.c b/src/vm/wren_compiler.c index 390c7250..c71dd7ec 100644 --- a/src/vm/wren_compiler.c +++ b/src/vm/wren_compiler.c @@ -1816,6 +1816,9 @@ static void list(Compiler* compiler, bool allowAssignment) { ignoreNewlines(compiler); + // List with trailing comma. + if (peek(compiler) == TOKEN_RIGHT_BRACKET) break; + // Push a copy of the list since the add() call will consume it. emit(compiler, CODE_DUP); diff --git a/test/language/list/trailing_comma.wren b/test/language/list/trailing_comma.wren new file mode 100644 index 00000000..a9995607 --- /dev/null +++ b/test/language/list/trailing_comma.wren @@ -0,0 +1,7 @@ +var list = [ + "a", + "b", +] + +IO.print(list[0]) // expect: a +IO.print(list[1]) // expect: b