Skip to content

Commit

Permalink
Fix missing syntax warning for using undefined gvar
Browse files Browse the repository at this point in the history
We normally issue a warning when code is parsed that uses a variable
identifier which has not yet been defined, which GAP then resolves as the
name of a gvar.

However, we suppress this warning if it is for the assignment to a global
variable.

But in some rare cases, this suppressed too much: if the very next line after
such an assignment wasn't an assignment itself, and accessed the gvar, we did
not print a warning.
  • Loading branch information
fingolfin committed Jun 29, 2018
1 parent 2890314 commit c58b257
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -830,11 +830,13 @@ static void ReadCallVarAss(TypSymbolSet follow, Char mode)
}
else {
Match( S_ASSIGN, ":=", follow );
UInt currLHSGVar = STATE(CurrLHSGVar);
if ( LEN_PLIST(STATE(StackNams)) == 0 || !STATE(IntrCoding) ) {
STATE(CurrLHSGVar) = (ref.type == R_GVAR ? ref.var : 0);
}
ReadExpr( follow, 'r' );
AssignRef(ref);
STATE(CurrLHSGVar) = currLHSGVar;
}
}

Expand Down
19 changes: 19 additions & 0 deletions tst/testbugfix/2018-06-29-CurrLHSGVar.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This always produced a warning"
gap> Unbind(string);
gap> for i in [ 1 .. 10 ] do
> string := "aaaabbbb";
> xxx := List( [], x -> string );
> od;
Syntax warning: Unbound global variable in stream:3
xxx := List( [], x -> string );
^

# ... but this did not; now it does
gap> Unbind(string);
gap> for i in [ 1 .. 10 ] do
> string := "aaaabbbb";
> List( [], x -> string );
> od;
Syntax warning: Unbound global variable in stream:3
List( [], x -> string );
^

0 comments on commit c58b257

Please sign in to comment.