Properly detect a missing "}" in a block.

Fix #429.
This commit is contained in:
Bob Nystrom
2017-10-08 10:03:42 -07:00
parent 18449102e8
commit c38d97b973
2 changed files with 9 additions and 5 deletions

View File

@ -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;
}

6
test/regression/429.wren Normal file
View File

@ -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