[ruby-core:86160] [Ruby trunk Bug#14611] Exotic method parameters bug

From: matthew@...
Date: 2018-03-16 15:11:34 UTC
List: ruby-core #86160
Issue #14611 has been updated by phluid61 (Matthew Kerwin).


bogdan (Bogdan Gusiev) wrote:
> 
> By some reason second parameter is nil when the rest of parameters declared as not used.

Underscore as "not used" here is a convention of Rubocop; your code is no different from:

~~~ruby
def test(a, x, *a)
  x
end
~~~

I would say the bug is that it didn't reject the `def` in the first place, because of the repeated parameter name.

----------------------------------------
Bug #14611: Exotic method parameters bug
https://bugs.ruby-lang.org/issues/14611#change-71039

* Author: bogdan (Bogdan Gusiev)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.4.2
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
Consider the following code:


~~~ ruby
def test(_, x, *_)
  x
end

test(1,2,3) # => nil
~~~

By some reason second parameter is nil when the rest of parameters declared as not used.




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next