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 #565.
pull/1005/head
Damien George 2014-12-11 17:35:23 +00:00
rodzic f905145c6d
commit c33ce606cf
1 zmienionych plików z 2 dodań i 2 usunięć

Wyświetl plik

@ -1796,7 +1796,8 @@ STATIC void compile_for_stmt_optimised_range(compiler_t *comp, mp_parse_node_t p
// at this point we actually have 1 less element on the stack
EMIT_ARG(adjust_stack_size, -1);
// store next value to var
// duplicate next value and store it to var
EMIT(dup_top);
c_assign(comp, pn_var, ASSIGN_STORE);
// compile body
@ -1805,7 +1806,6 @@ STATIC void compile_for_stmt_optimised_range(compiler_t *comp, mp_parse_node_t p
EMIT_ARG(label_assign, continue_label);
// compile: var + step, duplicated on stack
compile_node(comp, pn_var);
compile_node(comp, pn_step);
EMIT_ARG(binary_op, MP_BINARY_OP_INPLACE_ADD);
EMIT(dup_top);