Skip to content

Commit c33ce60

Browse files
committed
py: Fix a semantic issue with range optimisation.
Now you can assign to the range variable within the for loop and it will still work. Partially addresses issue adafruit#565.
1 parent f905145 commit c33ce60

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

py/compile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,7 +1796,8 @@ STATIC void compile_for_stmt_optimised_range(compiler_t *comp, mp_parse_node_t p
17961796
// at this point we actually have 1 less element on the stack
17971797
EMIT_ARG(adjust_stack_size, -1);
17981798

1799-
// store next value to var
1799+
// duplicate next value and store it to var
1800+
EMIT(dup_top);
18001801
c_assign(comp, pn_var, ASSIGN_STORE);
18011802

18021803
// compile body
@@ -1805,7 +1806,6 @@ STATIC void compile_for_stmt_optimised_range(compiler_t *comp, mp_parse_node_t p
18051806
EMIT_ARG(label_assign, continue_label);
18061807

18071808
// compile: var + step, duplicated on stack
1808-
compile_node(comp, pn_var);
18091809
compile_node(comp, pn_step);
18101810
EMIT_ARG(binary_op, MP_BINARY_OP_INPLACE_ADD);
18111811
EMIT(dup_top);

0 commit comments

Comments
 (0)