Skip to content

Commit 2cbd27e

Browse files
committed
Fix parser translator ast when using anonymous forwarding in blocks/lambda
Blocks and lambdas inherit anonymous arguments from the method they are a part of. They themselves don't allow to introduce new anonymous arguments. While you can write this: ```rb def foo(*) bar { |**| } end ``` referecing the new parameter inside of the block will always be a syntax error.
1 parent 8f086ac commit 2cbd27e

File tree

5 files changed

+637
-474
lines changed

5 files changed

+637
-474
lines changed

lib/prism/translation/parser/compiler.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ def visit_lambda_node(node)
11871187
false
11881188
)
11891189
end,
1190-
node.body&.accept(copy_compiler(forwarding: implicit_parameters ? [] : find_forwarding(parameters&.parameters))),
1190+
visit(node.body),
11911191
[node.closing, srange(node.closing_loc)]
11921192
)
11931193
end
@@ -2042,7 +2042,7 @@ def visit_block(call, block)
20422042
false
20432043
)
20442044
end,
2045-
block.body&.accept(copy_compiler(forwarding: implicit_parameters ? [] : find_forwarding(parameters&.parameters))),
2045+
visit(block.body),
20462046
token(block.closing_loc)
20472047
)
20482048
else

test/prism/fixtures/lambda.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010

1111
-> foo: bar do end
1212

13+
def foo(*, **)
14+
->() { bar(*, **) }
15+
end
16+
1317
p{|a:
1418
b|}
1519

test/prism/fixtures/methods.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ def foo = 123
109109

110110
def a(*); b(*); end
111111

112+
def a(*, **); b { c(*, **) }; end
113+
112114
def a(...); b(...); end
113115

114116
def a(...); b(1, 2, ...); end

test/prism/snapshots/lambda.txt

Lines changed: 123 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)