Skip to content

Commit 334c261

Browse files
Earlopainmatzbot
authored andcommitted
[ruby/prism] Fix parser translator when splatting in pattern matching pin
Because it ends up treating it as a local variable, and `a.x` is not a valid local variable name. I'm not big on pattern matching, but conceptually it makes sense to me to treat anything inside ^() to not be pattern matching syntax? ruby/prism@80dbd85c45
1 parent fe9ebb2 commit 334c261

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/prism/translation/parser/compiler.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,8 @@ def visit_parentheses_node(node)
14811481
# foo => ^(bar)
14821482
# ^^^^^^
14831483
def visit_pinned_expression_node(node)
1484-
expression = builder.begin(token(node.lparen_loc), visit(node.expression), token(node.rparen_loc))
1484+
parts = node.expression.accept(copy_compiler(in_pattern: false)) # Don't treat * and similar as match_rest
1485+
expression = builder.begin(token(node.lparen_loc), parts, token(node.rparen_loc))
14851486
builder.pin(token(node.operator_loc), expression)
14861487
end
14871488

test/prism/fixtures/patterns.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,7 @@ a in b, and c
218218
a in b, or c
219219
(a in b,) and c
220220
(a in b,) or c
221+
222+
x => ^([*a.x])
223+
x => ^([**a.x])
224+
x => ^({ a: })

0 commit comments

Comments
 (0)