diff options
| author | Benoit Daloze <eregontp@gmail.com> | 2026-01-20 21:20:06 +0100 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2026-01-21 13:21:37 +0000 |
| commit | 913ffcd1ddb854d2fdbf73a6ddf1930b8a472322 (patch) | |
| tree | 54e80d41045ee84c3e33a12452cfcbc3bfc91480 /lib | |
| parent | 519a4bdbc19693be9020419eb4dea9e66a256a41 (diff) | |
[ruby/prism] Check using Prism nodes if a command call has any arguments in Ripper translator
* We don't know what `on_*` events might return so we cannot assume it's an Array.
* See https://github.com/ruby/prism/issues/3838#issuecomment-3774702396
https://github.com/ruby/prism/commit/bed4271ce2
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/prism/translation/ripper.rb | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/prism/translation/ripper.rb b/lib/prism/translation/ripper.rb index afe30bb5db..41dd699438 100644 --- a/lib/prism/translation/ripper.rb +++ b/lib/prism/translation/ripper.rb @@ -1112,7 +1112,7 @@ module Prism else arguments, block = visit_call_node_arguments(node.arguments, node.block, trailing_comma?(node.arguments&.location || node.location, node.closing_loc || node.location)) call = - if node.opening_loc.nil? && arguments&.any? + if node.opening_loc.nil? && get_arguments_and_block(node.arguments, node.block).first.any? bounds(node.location) on_command(message, arguments) elsif !node.opening_loc.nil? @@ -1179,17 +1179,25 @@ module Prism end end - # Visit the arguments and block of a call node and return the arguments - # and block as they should be used. - private def visit_call_node_arguments(arguments_node, block_node, trailing_comma) + # Extract the arguments and block Ripper-style, which means if the block + # is like `&b` then it's moved to arguments. + private def get_arguments_and_block(arguments_node, block_node) arguments = arguments_node&.arguments || [] block = block_node if block.is_a?(BlockArgumentNode) - arguments << block + arguments += [block] block = nil end + [arguments, block] + end + + # Visit the arguments and block of a call node and return the arguments + # and block as they should be used. + private def visit_call_node_arguments(arguments_node, block_node, trailing_comma) + arguments, block = get_arguments_and_block(arguments_node, block_node) + [ if arguments.length == 1 && arguments.first.is_a?(ForwardingArgumentsNode) visit(arguments.first) |
