diff options
author | Kevin Newton <kddnewton@gmail.com> | 2024-03-06 00:46:34 -0500 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2024-03-06 16:42:59 +0000 |
commit | f75aa767f75a0ed8c10af31d07f2db875d26d420 (patch) | |
tree | 0a3755804afeaf1c2503fb879ce2859887b9d247 | |
parent | cdb47b1b3a641cc86092c2a60070752e10e873e8 (diff) |
[ruby/prism] Better handle splat in MRHS
https://github.com/ruby/prism/commit/8331874218
-rw-r--r-- | lib/prism/translation/ripper.rb | 5 | ||||
-rw-r--r-- | test/prism/ripper_test.rb | 3 |
2 files changed, 3 insertions, 5 deletions
diff --git a/lib/prism/translation/ripper.rb b/lib/prism/translation/ripper.rb index 79eaac3bd0..97274cabf9 100644 --- a/lib/prism/translation/ripper.rb +++ b/lib/prism/translation/ripper.rb @@ -2812,13 +2812,14 @@ module Prism length = elements.length bounds(elements.first.location) - elements.each_with_index.inject(on_args_new) do |args, (element, index)| + elements.each_with_index.inject((elements.first.is_a?(SplatNode) && length == 1) ? on_mrhs_new : on_args_new) do |args, (element, index)| arg = visit(element) bounds(element.location) if index == length - 1 if element.is_a?(SplatNode) - on_mrhs_add_star(on_mrhs_new_from_args(args), arg) + mrhs = index == 0 ? args : on_mrhs_new_from_args(args) + on_mrhs_add_star(mrhs, arg) else on_mrhs_add(on_mrhs_new_from_args(args), arg) end diff --git a/test/prism/ripper_test.rb b/test/prism/ripper_test.rb index 9b633c37cb..3dc900ff14 100644 --- a/test/prism/ripper_test.rb +++ b/test/prism/ripper_test.rb @@ -88,15 +88,12 @@ module Prism unparser/corpus/literal/while.txt unparser/corpus/semantic/dstr.txt unparser/corpus/semantic/while.txt - variables.txt - whitequark/asgn_mrhs.txt whitequark/bug_480.txt whitequark/dedenting_heredoc.txt whitequark/dedenting_interpolating_heredoc_fake_line_continuation.txt whitequark/dedenting_non_interpolating_heredoc_line_continuation.txt whitequark/empty_stmt.txt whitequark/if_elsif.txt - whitequark/masgn_splat.txt whitequark/parser_bug_640.txt whitequark/parser_drops_truncated_parts_of_squiggly_heredoc.txt whitequark/parser_slash_slash_n_escaping_in_literals.txt |