[ruby-core:74313] [Ruby trunk Bug#12073] local variable interferes with keyword arguments

From: xovatdev@...
Date: 2016-03-15 00:30:35 UTC
List: ruby-core #74313
Issue #12073 has been updated by Sean Linsley.


This is also an issue with array destructuring:

```ruby
def a(*b)
  b
end

a = [1,2,3]

a a
 => [[1, 2, 3]] 

a *a
TypeError: no implicit conversion of Array into Integer

a(*a)
 => [1, 2, 3]
```


----------------------------------------
Bug #12073: local variable interferes with keyword arguments
https://bugs.ruby-lang.org/issues/12073#change-57433

* Author: Josh Cheek
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-darwin13]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
This code causes a syntax error:

~~~
def a(b:)
  b
end
a = 1
a b: 9
 
# !> program.rb:5: syntax error, unexpected ':', expecting end-of-input
# !> a b: (9)
# !>     ^
~~~

However, if we remove the local assignment it works

~~~
def a(b:)
  b
end
a b: 9 # => 9
~~~

Or if we use parentheses it works

~~~
def a(b:)
  b
end
a = 1
a(b: 9) # => 9
~~~

Or if we use non-keyword arguments it works

~~~
def a(b)
  b
end
a = 1
a 9 # => 9
~~~



-- 
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