diff --git a/prism_compile.c b/prism_compile.c index df3e0c8659..654291170d 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -3177,7 +3177,9 @@ pm_compile_target_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *cons // // for i, j in []; end // + if (state != NULL) state->position--; pm_compile_multi_target_node(iseq, node, parents, writes, cleanup, src, scope_node, state); + if (state != NULL) state->position++; break; } default: @@ -3270,6 +3272,9 @@ pm_compile_multi_target_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR // Now, we need to go back and modify the topn instructions in order to // ensure they can correctly retrieve the parent expressions. pm_multi_target_state_update(&target_state); + + if (state != NULL) state->stack_size += target_state.stack_size; + return target_state.stack_size; } diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb index 682f50d1d6..6a30854ba8 100644 --- a/test/ruby/test_compile_prism.rb +++ b/test/ruby/test_compile_prism.rb @@ -653,6 +653,21 @@ module Prism foo = Foo.new _, foo.bar, _, foo.baz = 1 CODE + + # Test nested writes with method calls + assert_prism_eval(<<~RUBY) + class Foo + attr_accessor :bar + end + + a = Foo.new + + (a.bar, a.bar), b = [1], 2 + RUBY + assert_prism_eval(<<~RUBY) + h = {} + (h[:foo], h[:bar]), a = [1], 2 + RUBY end ############################################################################