From c38d97b973c608f54b226065ac68aa85a345c063 Mon Sep 17 00:00:00 2001 From: Bob Nystrom Date: Sun, 8 Oct 2017 10:03:42 -0700 Subject: [PATCH] Properly detect a missing "}" in a block. Fix #429. --- src/vm/wren_compiler.c | 8 +++----- test/regression/429.wren | 6 ++++++ 2 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 test/regression/429.wren diff --git a/src/vm/wren_compiler.c b/src/vm/wren_compiler.c index 4df6cbcd..4863b04b 100644 --- a/src/vm/wren_compiler.c +++ b/src/vm/wren_compiler.c @@ -1629,13 +1629,11 @@ static bool finishBlock(Compiler* compiler) do { definition(compiler); - - // If we got into a weird error state, don't get stuck in a loop. - if (peek(compiler) == TOKEN_EOF) return true; - consumeLine(compiler, "Expect newline after statement."); } - while (!match(compiler, TOKEN_RIGHT_BRACE)); + while (peek(compiler) != TOKEN_RIGHT_BRACE && peek(compiler) != TOKEN_EOF); + + consume(compiler, TOKEN_RIGHT_BRACE, "Expect '}' at end of block."); return false; } diff --git a/test/regression/429.wren b/test/regression/429.wren new file mode 100644 index 00000000..95106f42 --- /dev/null +++ b/test/regression/429.wren @@ -0,0 +1,6 @@ +// The missing "}" was not detected by the compiler and reported as an error, +// so it then tried to run the resulting erroneous bytecode and crashed. + +// expect error line 6 +{ +System \ No newline at end of file