Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress 'Unbound global variable' warning in IsBound #1334

Merged
merged 2 commits into from
May 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/read.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,16 +501,18 @@ void ReadCallVarAss (
if (WarnOnUnboundGlobalsRNam == 0)
WarnOnUnboundGlobalsRNam = RNamName("WarnOnUnboundGlobals");

if ( type == 'g'
&& STATE(CountNams) != 0
&& var != STATE(CurrLHSGVar)
&& VAL_GVAR(var) == 0
&& ExprGVar(var) == 0
&& ! STATE(IntrIgnoring)
&& ! GlobalComesFromEnclosingForLoop(var)
&& (GAPInfo == 0 || !IS_REC(GAPInfo) || !ISB_REC(GAPInfo,WarnOnUnboundGlobalsRNam) ||
ELM_REC(GAPInfo,WarnOnUnboundGlobalsRNam) != False )
&& ! SyCompilePlease )
if ( type == 'g' // Reading a global variable
&& mode != 'i' // Not inside 'IsBound'
&& STATE(CountNams) != 0 // Inside a function
&& var != STATE(CurrLHSGVar) // Not LHS of assignment
&& VAL_GVAR(var) == 0 // Not an existing global var
&& ExprGVar(var) == 0 // Or an auto var
&& ! STATE(IntrIgnoring) // Not currently ignoring parsed code
&& ! GlobalComesFromEnclosingForLoop(var) // Not loop variable
&& (GAPInfo == 0 || !IS_REC(GAPInfo)
|| !ISB_REC(GAPInfo,WarnOnUnboundGlobalsRNam) // Warning enabled
|| ELM_REC(GAPInfo,WarnOnUnboundGlobalsRNam) != False )
&& ! SyCompilePlease ) // Not compiling
{
SyntaxWarning("Unbound global variable");
}
Expand Down
17 changes: 17 additions & 0 deletions tst/testinstall/bound.tst
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,21 @@ gap> f := ( -> IsBound(r.b) );; f();
true
gap> f := ( -> IsBound(r.c) );; f();
false
gap> f := ( -> IsBound(BADVARNAME) );; f();
false
gap> f := ( -> IsBound(BADVARNAME.BADRECNAME) );;
gap> f();
Error, Variable: 'BADVARNAME' must have an assigned value
gap> f := ( -> BADVARNAME );;
Syntax warning: Unbound global variable in stream:1
f := ( -> BADVARNAME );;
^
gap> f();
Error, Variable: 'BADVARNAME' must have an assigned value
gap> f := ( -> IsBound(BADVARNAME[BADLISTNAME]) );;
Syntax warning: Unbound global variable in stream:1
f := ( -> IsBound(BADVARNAME[BADLISTNAME]) );;
^
gap> f();
Error, Variable: 'BADVARNAME' must have an assigned value
gap> STOP_TEST("bound.tst", 1);