Skip to content

Commit

Permalink
[ruby/prism] Handle numbered parameters in ripper translation
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton authored and matzbot committed Mar 6, 2024
1 parent f96ce41 commit cdb47b1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
8 changes: 4 additions & 4 deletions lib/prism/translation/ripper.rb
Expand Up @@ -1791,10 +1791,7 @@ def visit_keyword_rest_parameter_node(node)
# -> {}
def visit_lambda_node(node)
parameters =
if node.parameters.nil?
bounds(node.location)
on_params(nil, nil, nil, nil, nil, nil, nil)
else
if node.parameters.is_a?(BlockParametersNode)
# Ripper does not track block-locals within lambdas, so we skip
# directly to the parameters here.
params = visit(node.parameters.parameters)
Expand All @@ -1805,6 +1802,9 @@ def visit_lambda_node(node)
bounds(node.parameters.opening_loc)
on_paren(params)
end
else
bounds(node.location)
on_params(nil, nil, nil, nil, nil, nil, nil)
end

braces = node.opening == "{"
Expand Down
17 changes: 5 additions & 12 deletions test/prism/ripper_test.rb
Expand Up @@ -11,17 +11,14 @@ class RipperTest < TestCase
relatives = ENV["FOCUS"] ? [ENV["FOCUS"]] : Dir["**/*.txt", base: base]

incorrect = [
# Ripper incorrectly attributes the block to the `break` statement.
# Ripper incorrectly attributes the block to the keyword.
"seattlerb/block_break.txt",
"whitequark/break_block.txt",

# Ripper cannot handle named capture groups in regular expressions.
"whitequark/lvar_injecting_match.txt",

# Ripper incorrectly attributes the block to the `next` statement.
"whitequark/next_block.txt",
"whitequark/return_block.txt",

# Ripper incorrectly attributes the block to the `return` statement.
"whitequark/return_block.txt"
# Ripper cannot handle named capture groups in regular expressions.
"whitequark/lvar_injecting_match.txt"
]

skips = incorrect | %w[
Expand All @@ -39,7 +36,6 @@ class RipperTest < TestCase
regex_char_width.txt
rescue.txt
seattlerb/TestRubyParserShared.txt
seattlerb/block_break.txt
seattlerb/block_call_dot_op2_brace_block.txt
seattlerb/block_command_operation_colon.txt
seattlerb/block_command_operation_dot.txt
Expand Down Expand Up @@ -89,7 +85,6 @@ class RipperTest < TestCase
unparser/corpus/literal/module.txt
unparser/corpus/literal/pattern.txt
unparser/corpus/literal/send.txt
unparser/corpus/literal/since/27.txt
unparser/corpus/literal/while.txt
unparser/corpus/semantic/dstr.txt
unparser/corpus/semantic/while.txt
Expand All @@ -102,13 +97,11 @@ class RipperTest < TestCase
whitequark/empty_stmt.txt
whitequark/if_elsif.txt
whitequark/masgn_splat.txt
whitequark/numbered_args_after_27.txt
whitequark/parser_bug_640.txt
whitequark/parser_drops_truncated_parts_of_squiggly_heredoc.txt
whitequark/parser_slash_slash_n_escaping_in_literals.txt
whitequark/ruby_bug_11107.txt
whitequark/ruby_bug_11990.txt
whitequark/ruby_bug_15789.txt
whitequark/send_block_chain_cmd.txt
whitequark/slash_newline_in_heredocs.txt
whitequark/string_concat.txt
Expand Down

0 comments on commit cdb47b1

Please sign in to comment.