Skip to content

Commit cf21c08

Browse files
committed
Handle numbered parameters in ripper translation
1 parent dc74428 commit cf21c08

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

lib/prism/translation/ripper.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,10 +1791,7 @@ def visit_keyword_rest_parameter_node(node)
17911791
# -> {}
17921792
def visit_lambda_node(node)
17931793
parameters =
1794-
if node.parameters.nil?
1795-
bounds(node.location)
1796-
on_params(nil, nil, nil, nil, nil, nil, nil)
1797-
else
1794+
if node.parameters.is_a?(BlockParametersNode)
17981795
# Ripper does not track block-locals within lambdas, so we skip
17991796
# directly to the parameters here.
18001797
params = visit(node.parameters.parameters)
@@ -1805,6 +1802,9 @@ def visit_lambda_node(node)
18051802
bounds(node.parameters.opening_loc)
18061803
on_paren(params)
18071804
end
1805+
else
1806+
bounds(node.location)
1807+
on_params(nil, nil, nil, nil, nil, nil, nil)
18081808
end
18091809

18101810
braces = node.opening == "{"

test/prism/ripper_test.rb

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,14 @@ class RipperTest < TestCase
1111
relatives = ENV["FOCUS"] ? [ENV["FOCUS"]] : Dir["**/*.txt", base: base]
1212

1313
incorrect = [
14-
# Ripper incorrectly attributes the block to the `break` statement.
14+
# Ripper incorrectly attributes the block to the keyword.
15+
"seattlerb/block_break.txt",
1516
"whitequark/break_block.txt",
16-
17-
# Ripper cannot handle named capture groups in regular expressions.
18-
"whitequark/lvar_injecting_match.txt",
19-
20-
# Ripper incorrectly attributes the block to the `next` statement.
2117
"whitequark/next_block.txt",
18+
"whitequark/return_block.txt",
2219

23-
# Ripper incorrectly attributes the block to the `return` statement.
24-
"whitequark/return_block.txt"
20+
# Ripper cannot handle named capture groups in regular expressions.
21+
"whitequark/lvar_injecting_match.txt"
2522
]
2623

2724
skips = incorrect | %w[
@@ -39,7 +36,6 @@ class RipperTest < TestCase
3936
regex_char_width.txt
4037
rescue.txt
4138
seattlerb/TestRubyParserShared.txt
42-
seattlerb/block_break.txt
4339
seattlerb/block_call_dot_op2_brace_block.txt
4440
seattlerb/block_command_operation_colon.txt
4541
seattlerb/block_command_operation_dot.txt
@@ -89,7 +85,6 @@ class RipperTest < TestCase
8985
unparser/corpus/literal/module.txt
9086
unparser/corpus/literal/pattern.txt
9187
unparser/corpus/literal/send.txt
92-
unparser/corpus/literal/since/27.txt
9388
unparser/corpus/literal/while.txt
9489
unparser/corpus/semantic/dstr.txt
9590
unparser/corpus/semantic/while.txt
@@ -102,13 +97,11 @@ class RipperTest < TestCase
10297
whitequark/empty_stmt.txt
10398
whitequark/if_elsif.txt
10499
whitequark/masgn_splat.txt
105-
whitequark/numbered_args_after_27.txt
106100
whitequark/parser_bug_640.txt
107101
whitequark/parser_drops_truncated_parts_of_squiggly_heredoc.txt
108102
whitequark/parser_slash_slash_n_escaping_in_literals.txt
109103
whitequark/ruby_bug_11107.txt
110104
whitequark/ruby_bug_11990.txt
111-
whitequark/ruby_bug_15789.txt
112105
whitequark/send_block_chain_cmd.txt
113106
whitequark/slash_newline_in_heredocs.txt
114107
whitequark/string_concat.txt

0 commit comments

Comments
 (0)