diff options
| author | Kevin Newton <kddnewton@gmail.com> | 2024-06-04 14:17:21 -0400 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2024-06-04 20:28:53 +0000 |
| commit | bbf9b5baadaa476f72ae4d378841b3a63bdf7043 (patch) | |
| tree | 9bc371967f67a8a481024ba0b9b22a4d0d630665 | |
| parent | ac429df64fdec71ef705ddb984ad9f80ac03f249 (diff) | |
[ruby/prism] (parser) fix up nested multi write
https://github.com/ruby/prism/commit/12e079c97e
| -rw-r--r-- | lib/prism/translation/parser/compiler.rb | 22 | ||||
| -rw-r--r-- | test/prism/ruby/parser_test.rb | 2 |
2 files changed, 14 insertions, 10 deletions
diff --git a/lib/prism/translation/parser/compiler.rb b/lib/prism/translation/parser/compiler.rb index df5917ab26..78a15ad86e 100644 --- a/lib/prism/translation/parser/compiler.rb +++ b/lib/prism/translation/parser/compiler.rb @@ -1293,13 +1293,9 @@ module Prism # foo, bar = baz # ^^^^^^^^ def visit_multi_target_node(node) - elements = [*node.lefts] - elements << node.rest if !node.rest.nil? && !node.rest.is_a?(ImplicitRestNode) - elements.concat(node.rights) - builder.multi_lhs( token(node.lparen_loc), - visit_all(elements), + visit_all(multi_target_elements(node)), token(node.rparen_loc) ) end @@ -1307,9 +1303,11 @@ module Prism # foo, bar = baz # ^^^^^^^^^^^^^^ def visit_multi_write_node(node) - elements = [*node.lefts] - elements << node.rest if !node.rest.nil? && !node.rest.is_a?(ImplicitRestNode) - elements.concat(node.rights) + elements = multi_target_elements(node) + + if elements.length == 1 && elements.first.is_a?(MultiTargetNode) + elements = multi_target_elements(elements.first) + end builder.multi_assign( builder.multi_lhs( @@ -1921,6 +1919,14 @@ module Prism forwarding end + # Returns the set of targets for a MultiTargetNode or a MultiWriteNode. + def multi_target_elements(node) + elements = [*node.lefts] + elements << node.rest if !node.rest.nil? && !node.rest.is_a?(ImplicitRestNode) + elements.concat(node.rights) + elements + end + # Negate the value of a numeric node. This is a special case where you # have a negative sign on one line and then a number on the next line. # In normal Ruby, this will always be a method call. The parser gem, diff --git a/test/prism/ruby/parser_test.rb b/test/prism/ruby/parser_test.rb index d0e3288df7..c648d83bcf 100644 --- a/test/prism/ruby/parser_test.rb +++ b/test/prism/ruby/parser_test.rb @@ -59,7 +59,6 @@ module Prism "seattlerb/heredoc_with_extra_carriage_returns_windows.txt", "seattlerb/heredoc_with_only_carriage_returns_windows.txt", "seattlerb/heredoc_with_only_carriage_returns.txt", - "seattlerb/masgn_double_paren.txt", "seattlerb/parse_line_heredoc_hardnewline.txt", "seattlerb/pctW_lineno.txt", "seattlerb/regexp_esc_C_slash.txt", @@ -68,7 +67,6 @@ module Prism "unparser/corpus/literal/pattern.txt", "unparser/corpus/semantic/dstr.txt", "whitequark/dedenting_interpolating_heredoc_fake_line_continuation.txt", - "whitequark/masgn_nested.txt", "whitequark/parser_bug_640.txt", "whitequark/parser_slash_slash_n_escaping_in_literals.txt", "whitequark/ruby_bug_11989.txt", |
