summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEarlopain <[email protected]>2025-01-05 13:54:38 +0100
committerKevin Newton <[email protected]>2025-01-11 19:09:05 -0500
commitd1a70014f9a1ee411c41338d0929443bab004cda (patch)
tree7b18105f3d20fd93e97596b0aae5fbd7b660ec2c
parent7cbaa3b9298b4ab5027d75a7317ca43a9e745c16 (diff)
[ruby/prism] 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. https://github.com/ruby/prism/commit/2cbd27e134
-rw-r--r--lib/prism/translation/parser/compiler.rb4
-rw-r--r--test/prism/fixtures/lambda.txt4
-rw-r--r--test/prism/fixtures/methods.txt2
3 files changed, 8 insertions, 2 deletions
diff --git a/lib/prism/translation/parser/compiler.rb b/lib/prism/translation/parser/compiler.rb
index 3f0294bf62..54e08eb991 100644
--- a/lib/prism/translation/parser/compiler.rb
+++ b/lib/prism/translation/parser/compiler.rb
@@ -1187,7 +1187,7 @@ module Prism
false
)
end,
- node.body&.accept(copy_compiler(forwarding: implicit_parameters ? [] : find_forwarding(parameters&.parameters))),
+ visit(node.body),
[node.closing, srange(node.closing_loc)]
)
end
@@ -2042,7 +2042,7 @@ module Prism
false
)
end,
- block.body&.accept(copy_compiler(forwarding: implicit_parameters ? [] : find_forwarding(parameters&.parameters))),
+ visit(block.body),
token(block.closing_loc)
)
else
diff --git a/test/prism/fixtures/lambda.txt b/test/prism/fixtures/lambda.txt
index dfe833509f..8d67b4dd79 100644
--- a/test/prism/fixtures/lambda.txt
+++ b/test/prism/fixtures/lambda.txt
@@ -10,6 +10,10 @@
-> foo: bar do end
+def foo(*, **)
+ ->() { bar(*, **) }
+end
+
p{|a:
b|}
diff --git a/test/prism/fixtures/methods.txt b/test/prism/fixtures/methods.txt
index d59196bdfd..eb0a5ca3dc 100644
--- a/test/prism/fixtures/methods.txt
+++ b/test/prism/fixtures/methods.txt
@@ -109,6 +109,8 @@ def foo = 123
def a(*); b(*); end
+def a(*, **); b { c(*, **) }; end
+
def a(...); b(...); end
def a(...); b(1, 2, ...); end