mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 14:18:42 +01:00
Set the token type after an invalid character error.
Otherwise, it still has the previous token's type. This can cause it to get stuck in a loop in some places in the compiler. Fix #428.
This commit is contained in:
@ -407,10 +407,7 @@ static void printError(Parser* parser, int line, const char* label,
|
||||
parser->module->name->value, line, message);
|
||||
}
|
||||
|
||||
// Outputs a compile or syntax error. This also marks the compilation as having
|
||||
// an error, which ensures that the resulting code will be discarded and never
|
||||
// run. This means that after calling lexError(), it's fine to generate whatever
|
||||
// invalid bytecode you want since it won't be used.
|
||||
// Outputs a lexical error.
|
||||
static void lexError(Parser* parser, const char* format, ...)
|
||||
{
|
||||
va_list args;
|
||||
@ -1073,9 +1070,22 @@ static void nextToken(Parser* parser)
|
||||
readNumber(parser);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (c >= 32 && c <= 126)
|
||||
{
|
||||
lexError(parser, "Invalid character '%c'.", c);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Don't show non-ASCII values since we didn't UTF-8 decode the
|
||||
// bytes. Since there are no non-ASCII byte values that are
|
||||
// meaningful code units in Wren, the lexer works on raw bytes,
|
||||
// even though the source code and console output are UTF-8.
|
||||
lexError(parser, "Invalid byte 0x%x.", (uint8_t)c);
|
||||
}
|
||||
parser->current.type = TOKEN_ERROR;
|
||||
parser->current.length = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
6
test/regression/428.wren
Normal file
6
test/regression/428.wren
Normal file
@ -0,0 +1,6 @@
|
||||
// This was crashing the compiler with an out of bounds memory access.
|
||||
|
||||
// expect error line 6
|
||||
// expect error line 7
|
||||
Fiber.new {
|
||||
isDone ["", àààààààààààààààààààààààààààààààààààààààààààààààààà
|
||||
Reference in New Issue
Block a user