diff --git a/src/location.c b/src/location.c index 9f929c00..4b7273d2 100644 --- a/src/location.c +++ b/src/location.c @@ -175,6 +175,8 @@ location_print (location loc, FILE *out) } else { + aver (loc.start.file); + aver (loc.end.file); int end_col = 0 != loc.end.column ? loc.end.column - 1 : 0; res += fprintf (out, "%s", quotearg_n_style (3, escape_quoting_style, loc.start.file)); diff --git a/src/symtab.c b/src/symtab.c index b137bbf0..b4106ea0 100644 --- a/src/symtab.c +++ b/src/symtab.c @@ -555,7 +555,10 @@ symbol_class_set (symbol *sym, symbol_class class, location loc, bool declaring) _("previous declaration")); } else - s->status = declared; + { + sym->location = loc; + s->status = declared; + } } } } diff --git a/tests/input.at b/tests/input.at index 4c1f5b25..dd5af739 100644 --- a/tests/input.at +++ b/tests/input.at @@ -298,6 +298,37 @@ input.y:8.14: error: syntax error, unexpected integer AT_CLEANUP +## ---------------------------- ## +## Redefining the error token. ## +## ---------------------------- ## + +AT_SETUP([Redefining the error token]) + +# We used to crash when trying to display the original definition of +# "error", which is a builtin without any location. + +AT_DATA([input.y], +[[%token error 123 +%token error 124 +%% +exp: +]]) + +AT_BISON_CHECK([-fcaret input.y], [1], [], +[[input.y:2.8-12: warning: symbol error redeclared [-Wother] + 2 | %token error 124 + | ^~~~~ +input.y:1.8-12: previous declaration + 1 | %token error 123 + | ^~~~~ +input.y:2.14-16: error: redefining user token number of error + 2 | %token error 124 + | ^~~ +]]) + +AT_CLEANUP + + ## ------------------ ## ## Dangling aliases. ## ## ------------------ ##