@@ -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