authorgravatar for matthew.mcallister.0@gmail.comMatthew McAllister <matthew.mcallister.0@gmail.com> 2019-01-29 16:20:38-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-01-30 14:02:01-05:00
logad8381e0d2936ffecaa0b54e51e26d6bdb98682e
treeb7a51c0044311876c296f30a2e46762f6a80e0ad
parentecb0cb661a75a130cf6978fa42d464e2d654d8df

Move tokenizer error location to offending char

Previously, it pointed to the start of the current token, but this made it difficult to tell where the error occurred when it was, say, in the middle of a string.

2 files changed, 3 insertions(+), 8 deletions(-)

src/tokenizer.cpp+2-7
......@@ -248,13 +248,8 @@ ATTRIBUTE_PRINTF(2, 3)
248248static void tokenize_error(Tokenize *t, const char *format, ...) {
249249 t->state = TokenizeStateError;
250250
251 if (t->cur_tok) {
252 t->out->err_line = t->cur_tok->start_line;
253 t->out->err_column = t->cur_tok->start_column;
254 } else {
255 t->out->err_line = t->line;
256 t->out->err_column = t->column;
257 }
251 t->out->err_line = t->line;
252 t->out->err_column = t->column;
258253
259254 va_list ap;
260255 va_start(ap, format);
test/compile_errors.zig+1-1
......@@ -2645,7 +2645,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
26452645 \\
26462646 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
26472647 ,
2648 ".tmp_source.zig:1:13: error: newline not allowed in string literal",
2648 ".tmp_source.zig:1:15: error: newline not allowed in string literal",
26492649 );
26502650
26512651 cases.add(