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 Sep 21, 2018
1 parent 2ba0291 commit f304c01
Show file tree
Hide file tree
Showing 3 changed files with 22 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 @@ -806,11 +806,13 @@ static void ReadCallVarAss(TypSymbolSet follow, Char mode)
}
else {
Match( S_ASSIGN, ":=", follow );
UInt currLHSGVar = ReaderState()->CurrLHSGVar;
if ( LEN_PLIST(STATE(StackNams)) == 0 || !STATE(IntrCoding) ) {
ReaderState()->CurrLHSGVar = (ref.type == R_GVAR ? ref.var : 0);
}
ReadExpr( follow, 'r' );
AssignRef(ref);
ReaderState()->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 );
^
1 change: 1 addition & 0 deletions tst/teststandard/ctblsymm.tst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ gap> c3:= CharacterTable( CyclicGroup( 3 ) );;
gap> n:= 3;;
gap> wr:= CharacterTableWreathSymmetric( c3, n );;
gap> irr:= Irr( wr );;
gap> betas:=fail;;
gap> for i in [ 1 .. Length( irr ) ] do
> betas:= List( CharacterParameters( wr )[i], BetaSet );
> if List( ClassParameters( wr ),
Expand Down

0 comments on commit f304c01

Please sign in to comment.