Skip to content

Commit 529700d

Browse files
committed
[PRISM] Nested MultiWriteNode with method calls
Fixes ruby/prism#2247.
1 parent d86c4e5 commit 529700d

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

prism_compile.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3177,7 +3177,9 @@ pm_compile_target_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *cons
31773177
//
31783178
// for i, j in []; end
31793179
//
3180+
if (state != NULL) state->position--;
31803181
pm_compile_multi_target_node(iseq, node, parents, writes, cleanup, src, scope_node, state);
3182+
if (state != NULL) state->position++;
31813183
break;
31823184
}
31833185
default:
@@ -3270,6 +3272,9 @@ pm_compile_multi_target_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR
32703272
// Now, we need to go back and modify the topn instructions in order to
32713273
// ensure they can correctly retrieve the parent expressions.
32723274
pm_multi_target_state_update(&target_state);
3275+
3276+
if (state != NULL) state->stack_size += target_state.stack_size;
3277+
32733278
return target_state.stack_size;
32743279
}
32753280

test/ruby/test_compile_prism.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,21 @@ def baz=(c); end
653653
foo = Foo.new
654654
_, foo.bar, _, foo.baz = 1
655655
CODE
656+
657+
# Test nested writes with method calls
658+
assert_prism_eval(<<~RUBY)
659+
class Foo
660+
attr_accessor :bar
661+
end
662+
663+
a = Foo.new
664+
665+
(a.bar, a.bar), b = [1], 2
666+
RUBY
667+
assert_prism_eval(<<~RUBY)
668+
h = {}
669+
(h[:foo], h[:bar]), a = [1], 2
670+
RUBY
656671
end
657672

658673
############################################################################

0 commit comments

Comments
 (0)