Skip to content

Commit

Permalink
[ruby/prism] Fix up forwarding arguments for 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 e97b364 commit 8f7db7e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
10 changes: 6 additions & 4 deletions lib/prism/translation/ripper.rb
Expand Up @@ -248,7 +248,6 @@ def visit_array_node(node)
# Visit a list of elements, like the elements of an array or arguments.
private def visit_arguments(elements)
bounds(elements.first.location)

elements.inject(on_args_new) do |args, element|
arg = visit(element)
bounds(element.location)
Expand Down Expand Up @@ -626,10 +625,12 @@ def visit_call_node(node)
end

arguments =
if arguments.any?
if arguments.length == 1 && arguments.first.is_a?(ForwardingArgumentsNode)
visit(arguments.first)
elsif arguments.any?
args = visit_arguments(arguments)

if block.is_a?(BlockArgumentNode)
if block.is_a?(BlockArgumentNode) || arguments.last.is_a?(ForwardingArgumentsNode)
args
else
bounds(arguments.first.location)
Expand Down Expand Up @@ -1208,7 +1209,8 @@ def visit_for_node(node)
# def foo(...); bar(...); end
# ^^^
def visit_forwarding_arguments_node(node)
raise NoMethodError, __method__
bounds(node.location)
on_args_forward
end

# def foo(...); end
Expand Down
3 changes: 0 additions & 3 deletions test/prism/ripper_test.rb
Expand Up @@ -90,7 +90,6 @@ class RipperTest < TestCase
seattlerb/defn_arg_forward_args.txt
seattlerb/defn_args_forward_args.txt
seattlerb/defn_forward_args.txt
seattlerb/defn_forward_args__no_parens.txt
seattlerb/defn_kwarg_lvar.txt
seattlerb/defn_oneliner_eq2.txt
seattlerb/defn_oneliner_rescue.txt
Expand Down Expand Up @@ -311,11 +310,9 @@ class RipperTest < TestCase
whitequark/empty_stmt.txt
whitequark/endless_method.txt
whitequark/endless_method_command_syntax.txt
whitequark/endless_method_forwarded_args_legacy.txt
whitequark/endless_method_with_rescue_mod.txt
whitequark/endless_method_without_args.txt
whitequark/forward_arg.txt
whitequark/forward_arg_with_open_args.txt
whitequark/forward_args_legacy.txt
whitequark/forwarded_argument_with_kwrestarg.txt
whitequark/forwarded_argument_with_restarg.txt
Expand Down

0 comments on commit 8f7db7e

Please sign in to comment.