Proper error message when jumping into 'global *'

A goto cannot jump into the scope of any variable declaration,
including 'global *'. To report the error, it needs a "name" for
the scope it is entering.
This commit is contained in:
Roberto Ierusalimschy
2025-05-18 12:03:54 -03:00
parent abbae57c78
commit 6d53701c7a
3 changed files with 12 additions and 9 deletions

View File

@@ -542,13 +542,13 @@ static void adjust_assign (LexState *ls, int nvars, int nexps, expdesc *e) {
/*
** Generates an error that a goto jumps into the scope of some
** local variable.
** variable declaration.
*/
static l_noret jumpscopeerror (LexState *ls, Labeldesc *gt) {
TString *tsname = getlocalvardesc(ls->fs, gt->nactvar)->vd.name;
const char *varname = getstr(tsname);
const char *varname = (tsname != NULL) ? getstr(tsname) : "*";
luaK_semerror(ls,
"<goto %s> at line %d jumps into the scope of local '%s'",
"<goto %s> at line %d jumps into the scope of '%s'",
getstr(gt->name), gt->line, varname); /* raise the error */
}