diff options
author | Peter Zhu <peter@peterzhu.ca> | 2024-01-23 11:32:35 -0500 |
---|---|---|
committer | Peter Zhu <peter@peterzhu.ca> | 2024-01-24 10:08:25 -0500 |
commit | 529700d3145cc77271a70bc75ab91528b7a7b084 (patch) | |
tree | eb72c302b359a7f0259e103169d7f009ce7320bd | |
parent | d86c4e553ee8ff899a103a49db0b66c73c01135f (diff) | |
download | ruby-529700d3145cc77271a70bc75ab91528b7a7b084.tar.gz |
[PRISM] Nested MultiWriteNode with method calls
Fixes ruby/prism#2247.
-rw-r--r-- | prism_compile.c | 5 | ||||
-rw-r--r-- | test/ruby/test_compile_prism.rb | 15 |
2 files changed, 20 insertions, 0 deletions
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 ############################################################################ |