Skip to content

Commit 8331874

Browse files
committed
Better handle splat in MRHS
1 parent cf21c08 commit 8331874

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

lib/prism/translation/ripper.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2812,13 +2812,14 @@ def visit_write_value(node)
28122812
length = elements.length
28132813

28142814
bounds(elements.first.location)
2815-
elements.each_with_index.inject(on_args_new) do |args, (element, index)|
2815+
elements.each_with_index.inject((elements.first.is_a?(SplatNode) && length == 1) ? on_mrhs_new : on_args_new) do |args, (element, index)|
28162816
arg = visit(element)
28172817
bounds(element.location)
28182818

28192819
if index == length - 1
28202820
if element.is_a?(SplatNode)
2821-
on_mrhs_add_star(on_mrhs_new_from_args(args), arg)
2821+
mrhs = index == 0 ? args : on_mrhs_new_from_args(args)
2822+
on_mrhs_add_star(mrhs, arg)
28222823
else
28232824
on_mrhs_add(on_mrhs_new_from_args(args), arg)
28242825
end

test/prism/ripper_test.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,12 @@ class RipperTest < TestCase
8888
unparser/corpus/literal/while.txt
8989
unparser/corpus/semantic/dstr.txt
9090
unparser/corpus/semantic/while.txt
91-
variables.txt
92-
whitequark/asgn_mrhs.txt
9391
whitequark/bug_480.txt
9492
whitequark/dedenting_heredoc.txt
9593
whitequark/dedenting_interpolating_heredoc_fake_line_continuation.txt
9694
whitequark/dedenting_non_interpolating_heredoc_line_continuation.txt
9795
whitequark/empty_stmt.txt
9896
whitequark/if_elsif.txt
99-
whitequark/masgn_splat.txt
10097
whitequark/parser_bug_640.txt
10198
whitequark/parser_drops_truncated_parts_of_squiggly_heredoc.txt
10299
whitequark/parser_slash_slash_n_escaping_in_literals.txt

0 commit comments

Comments
 (0)