Boo

Allow reuse of local in "for in" loops.

Details

  • Type: Improvement Improvement
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 0.8.2
  • Fix Version/s: 0.9
  • Component/s: Compiler
  • Labels:
    None
  • Testcase included:
    yes
  • Number of attachments :
    0

Description

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

Activity

Hide
Cedric Vivier added a comment -

Add a range testcase with step=-2.

Show
Cedric Vivier added a comment - Add a range testcase with step=-2.
Hide
Cedric Vivier added a comment -

Fixed in rev. 3097

Show
Cedric Vivier added a comment - Fixed in rev. 3097

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: