diff --git a/lib/prism/translation/parser/compiler.rb b/lib/prism/translation/parser/compiler.rb index 388bd4687d..e032c3a97f 100644 --- a/lib/prism/translation/parser/compiler.rb +++ b/lib/prism/translation/parser/compiler.rb @@ -1313,7 +1313,7 @@ def visit_multi_target_node(node) def visit_multi_write_node(node) elements = multi_target_elements(node) - if elements.length == 1 && elements.first.is_a?(MultiTargetNode) + if elements.length == 1 && elements.first.is_a?(MultiTargetNode) && !node.rest elements = multi_target_elements(elements.first) end diff --git a/test/prism/fixtures/variables.txt b/test/prism/fixtures/variables.txt index 1545c30c80..4f4dc6f9c8 100644 --- a/test/prism/fixtures/variables.txt +++ b/test/prism/fixtures/variables.txt @@ -45,3 +45,5 @@ Foo = 1, 2 (a; b; c) a, (b, c), d = [] + +(a,), = [] diff --git a/test/prism/snapshots/variables.txt b/test/prism/snapshots/variables.txt index 3cb0ada657..2affa7ff8a 100644 --- a/test/prism/snapshots/variables.txt +++ b/test/prism/snapshots/variables.txt @@ -1,10 +1,10 @@ -@ ProgramNode (location: (1,0)-(47,17)) +@ ProgramNode (location: (1,0)-(49,10)) ├── flags: ∅ ├── locals: [:abc, :foo, :bar, :baz, :a, :b, :c, :d] └── statements: - @ StatementsNode (location: (1,0)-(47,17)) + @ StatementsNode (location: (1,0)-(49,10)) ├── flags: ∅ - └── body: (length: 25) + └── body: (length: 26) ├── @ ClassVariableReadNode (location: (1,0)-(1,5)) │ ├── flags: newline │ └── name: :@@abc @@ -420,40 +420,69 @@ │ │ └── block: ∅ │ ├── opening_loc: (45,0)-(45,1) = "(" │ └── closing_loc: (45,8)-(45,9) = ")" - └── @ MultiWriteNode (location: (47,0)-(47,17)) + ├── @ MultiWriteNode (location: (47,0)-(47,17)) + │ ├── flags: newline + │ ├── lefts: (length: 3) + │ │ ├── @ LocalVariableTargetNode (location: (47,0)-(47,1)) + │ │ │ ├── flags: ∅ + │ │ │ ├── name: :a + │ │ │ └── depth: 0 + │ │ ├── @ MultiTargetNode (location: (47,3)-(47,9)) + │ │ │ ├── flags: ∅ + │ │ │ ├── lefts: (length: 2) + │ │ │ │ ├── @ LocalVariableTargetNode (location: (47,4)-(47,5)) + │ │ │ │ │ ├── flags: ∅ + │ │ │ │ │ ├── name: :b + │ │ │ │ │ └── depth: 0 + │ │ │ │ └── @ LocalVariableTargetNode (location: (47,7)-(47,8)) + │ │ │ │ ├── flags: ∅ + │ │ │ │ ├── name: :c + │ │ │ │ └── depth: 0 + │ │ │ ├── rest: ∅ + │ │ │ ├── rights: (length: 0) + │ │ │ ├── lparen_loc: (47,3)-(47,4) = "(" + │ │ │ └── rparen_loc: (47,8)-(47,9) = ")" + │ │ └── @ LocalVariableTargetNode (location: (47,11)-(47,12)) + │ │ ├── flags: ∅ + │ │ ├── name: :d + │ │ └── depth: 0 + │ ├── rest: ∅ + │ ├── rights: (length: 0) + │ ├── lparen_loc: ∅ + │ ├── rparen_loc: ∅ + │ ├── operator_loc: (47,13)-(47,14) = "=" + │ └── value: + │ @ ArrayNode (location: (47,15)-(47,17)) + │ ├── flags: static_literal + │ ├── elements: (length: 0) + │ ├── opening_loc: (47,15)-(47,16) = "[" + │ └── closing_loc: (47,16)-(47,17) = "]" + └── @ MultiWriteNode (location: (49,0)-(49,10)) ├── flags: newline - ├── lefts: (length: 3) - │ ├── @ LocalVariableTargetNode (location: (47,0)-(47,1)) - │ │ ├── flags: ∅ - │ │ ├── name: :a - │ │ └── depth: 0 - │ ├── @ MultiTargetNode (location: (47,3)-(47,9)) - │ │ ├── flags: ∅ - │ │ ├── lefts: (length: 2) - │ │ │ ├── @ LocalVariableTargetNode (location: (47,4)-(47,5)) - │ │ │ │ ├── flags: ∅ - │ │ │ │ ├── name: :b - │ │ │ │ └── depth: 0 - │ │ │ └── @ LocalVariableTargetNode (location: (47,7)-(47,8)) - │ │ │ ├── flags: ∅ - │ │ │ ├── name: :c - │ │ │ └── depth: 0 - │ │ ├── rest: ∅ - │ │ ├── rights: (length: 0) - │ │ ├── lparen_loc: (47,3)-(47,4) = "(" - │ │ └── rparen_loc: (47,8)-(47,9) = ")" - │ └── @ LocalVariableTargetNode (location: (47,11)-(47,12)) + ├── lefts: (length: 1) + │ └── @ MultiTargetNode (location: (49,0)-(49,4)) │ ├── flags: ∅ - │ ├── name: :d - │ └── depth: 0 - ├── rest: ∅ + │ ├── lefts: (length: 1) + │ │ └── @ LocalVariableTargetNode (location: (49,1)-(49,2)) + │ │ ├── flags: ∅ + │ │ ├── name: :a + │ │ └── depth: 0 + │ ├── rest: + │ │ @ ImplicitRestNode (location: (49,2)-(49,3)) + │ │ └── flags: ∅ + │ ├── rights: (length: 0) + │ ├── lparen_loc: (49,0)-(49,1) = "(" + │ └── rparen_loc: (49,3)-(49,4) = ")" + ├── rest: + │ @ ImplicitRestNode (location: (49,4)-(49,5)) + │ └── flags: ∅ ├── rights: (length: 0) ├── lparen_loc: ∅ ├── rparen_loc: ∅ - ├── operator_loc: (47,13)-(47,14) = "=" + ├── operator_loc: (49,6)-(49,7) = "=" └── value: - @ ArrayNode (location: (47,15)-(47,17)) + @ ArrayNode (location: (49,8)-(49,10)) ├── flags: static_literal ├── elements: (length: 0) - ├── opening_loc: (47,15)-(47,16) = "[" - └── closing_loc: (47,16)-(47,17) = "]" + ├── opening_loc: (49,8)-(49,9) = "[" + └── closing_loc: (49,9)-(49,10) = "]"