Re: Phix loop variables and scope

new topic     » goto parent     » topic index » view thread      » older message » newer message

This works fine in phix:

procedure p() 
integer x=0  
  
for x=2 to 7 do  
    ?x  
end for  
  
?x  
end procedure 
p() 

So I have classed this as a bug, which needed the following change to psym.e, line 3085 in routine InTable():

--25/5/18: 
--          if spNTyp=S_TVar then 
            if spNTyp=S_TVar  
            or (returnvar=-1 and spNTyp=S_GVar2) then 

which makes it work the same without the p() wrapper, and does not break any of the tests.

Note that using local namespaces does not work very well in phix: I had no idea they were even supposed to until last year,
and I'm still not sure, as in theory they should not make anything behave any differently whether present or not anyway.

Pete

PS:

namespace mine  
  
integer mine:x  

I would not expect that to work at all. Namespaces qualify references, not declarations.
I concede it is an odd error message, but there would be little benefit in fixing that.

PPS: In phix, pre-declaring the control loop variable makes it persist beyond the end for, in this case with a value of 8.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu