From cf21c08c0b48a6be6d2f4faccdf2a07b2328b0e6 Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Wed, 6 Mar 2024 00:41:07 -0500 Subject: [PATCH] Handle numbered parameters in ripper translation --- lib/prism/translation/ripper.rb | 8 ++++---- test/prism/ripper_test.rb | 17 +++++------------ 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/lib/prism/translation/ripper.rb b/lib/prism/translation/ripper.rb index be4032de8d6..79eaac3bd0b 100644 --- a/lib/prism/translation/ripper.rb +++ b/lib/prism/translation/ripper.rb @@ -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) @@ -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 == "{" diff --git a/test/prism/ripper_test.rb b/test/prism/ripper_test.rb index 076bcef0851..9b633c37cbc 100644 --- a/test/prism/ripper_test.rb +++ b/test/prism/ripper_test.rb @@ -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[ @@ -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 @@ -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 @@ -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