Skip to content

Commit 62dbc11

Browse files
Update for_helpers.py
1 parent 9f2cc4b commit 62dbc11

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

mypyc/irbuild/for_helpers.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ def for_loop_helper_with_index(
178178
exit_block = BasicBlock()
179179
condition_block = BasicBlock()
180180

181-
for_gen = ForSequence(builder, index, body_block, exit_block, line, False, length)
182-
for_gen.init(expr_reg, target_type, reverse=False)
181+
for_gen = ForSequence(builder, index, body_block, exit_block, line, False)
182+
for_gen.init(expr_reg, target_type, reverse=False, length=length)
183183

184184
builder.push_loop_stack(step_block, exit_block)
185185

@@ -796,9 +796,11 @@ class ForSequence(ForGenerator):
796796

797797
length_reg: Value | AssignmentTarget | None
798798

799-
def init(self, expr_reg: Value, target_type: RType, reverse: bool) -> None:
799+
def init(self, expr_reg: Value, target_type: RType, reverse: bool, length: Value | None = None) -> None:
800800
assert is_sequence_rprimitive(expr_reg.type), expr_reg
801801
builder = self.builder
802+
# Record a Value indicating the length of the sequence, if known at compile time.
803+
self.length = length
802804
self.reverse = reverse
803805
# Define target to contain the expression, along with the index that will be used
804806
# for the for-loop. If we are inside of a generator function, spill these into the

0 commit comments

Comments
 (0)