diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ChangeLog | 7 | ||||
-rw-r--r-- | src/interp/compiler.boot | 11 |
2 files changed, 17 insertions, 1 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 99d8b460..e9dd5d4b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,12 @@ 2010-06-12 Gabriel Dos Reis <gdr@cs.tamu.edu> + * interp/compiler.boot (complainIfShadowing): New. + (compStepIterator): Use it to warn about loop variable shadowing + declaration in enclosing scope. + (compIterator): Likewise. + +2010-06-12 Gabriel Dos Reis <gdr@cs.tamu.edu> + * algebra/kl.spad.pamphlet (Kernel): Don't clear the on instanstiation, for that may erase other precious information in the running seesion when Kernel is implicitly re-instantiated by diff --git a/src/interp/compiler.boot b/src/interp/compiler.boot index 87d07c89..ceae230f 100644 --- a/src/interp/compiler.boot +++ b/src/interp/compiler.boot @@ -2362,12 +2362,19 @@ compIntegerValue(x,e) == comp(x,$PositiveInteger,e) or comp(x,$NonNegativeInteger,e) or compOrCroak(x,$Integer,e) - + +++ Issue a diagnostic if `x' names a loop variable with a matching +++ declaration or definition in the enclosing scope. +complainIfShadowing(x,e) == + if getmode(x,e) ~= nil then + stackWarning('"loop variable %1b shadows variable from enclosing scope",[x]) + ++ Attempt to compile a `for' iterator of the form ++ for index in start..final by inc ++ where the bound `final' may be missing. compStepIterator(index,start,final,inc,e) == checkVariableName index + complainIfShadowing(index,e) $formalArgList := [index,:$formalArgList] [start,startMode,e] := compIntegerValue(start,e) or return stackMessage('"start value of index: %1b must be an integer",[start]) @@ -2389,6 +2396,7 @@ compIterator(it,e) == -- ??? Allow for declared iterator variable. it is ["IN",x,y] => checkVariableName x + complainIfShadowing(x,e) --these two lines must be in this order, to get "for f in list f" --to give an error message if f is undefined [y',m,e]:= comp(y,$EmptyMode,e) or return nil @@ -2403,6 +2411,7 @@ compIterator(it,e) == [["IN",x,y''],e] it is ["ON",x,y] => checkVariableName x + complainIfShadowing(x,e) $formalArgList:= [x,:$formalArgList] [y',m,e]:= comp(y,$EmptyMode,e) or return nil [mOver,mUnder]:= |