Project

General

Profile

Actions

Bug #15457

closed

Weird behaviour when having multiple arguments of same name and splat operator

Added by graywolf (Gray Wolf) over 5 years ago. Updated over 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
2.5.3
[ruby-core:90690]

Description

When multiple arguments of the same name are provided and last one of
them has splat operator, everything gets weird.

+   $ cat bug.rb
def test(_a, b, *_a)
  pp _a
  pp b
end
test(*%W{a b c d e})

+   $ RUBYOPT=-rpry rvm 2.5.3 do ruby bug.rb
["c", "d", "e"]
nil

+   $ RUBYOPT=-rpry rvm 2.4.5 do ruby bug.rb
["c", "d", "e"]
nil

+   $ RUBYOPT=-rpry rvm 2.3.8 do ruby bug.rb
["c", "d", "e"]
nil

At least it's consistent across supported ruby versions, but I have no
idea what is going on.

I get why _a is %w{c d e}, that makes sense. But why is b nil?
That makes no sense at all.

It looks to me like an edge case when having multiple arguments of the same
name and one of them (last one?) having splat operator.


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #14611: Exotic method parameters bugClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0