Issue Details (XML | Word | Printable)

Key: BOO-1111
Type: Improvement Improvement
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Cedric Vivier
Reporter: Cedric Vivier
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Boo

Allow reuse of local in "for in" loops.

Created: 12/Jan/09 09:18 AM   Updated: 13/Jan/09 04:18 AM   Resolved: 13/Jan/09 04:18 AM
Return to search
Component/s: Compiler
Affects Version/s: 0.8.2
Fix Version/s: 0.9

Time Tracking:
Not Specified

Testcase included: yes


 Description  « Hide

Currently Boo creates a new local for the sole usage of one "for loop" even if a local with the same name have been declared before.

def Foo():
    yield 1
    yield 2

x = 0
for x in Foo():      #generated IL is actually "for x2 in.." or whatever.
    pass
print x  #prints 0

Boo should reuse a local when it has been declared earlier in the body (including in the optimized case of "for in range").

Testcase:

"""
2
9
2
5
"""

def Foo():
    yield 1
    yield 2

x = 0
for x in Foo():
    pass
print x

j = 0
for j in range(10):
    pass
print j

for i in range(10, 0, -2):
    pass
print j

for j in (1, 1, 2, 3, 5):
    pass
print j


Cedric Vivier added a comment - 12/Jan/09 10:06 AM

Add a range testcase with step=-2.


Cedric Vivier added a comment - 13/Jan/09 04:18 AM

Fixed in rev. 3097