[ruby-core:76064] [Ruby trunk Bug#12501] Assignment to local variable itself doesn't occur an error
From:
scorix@...
Date:
2016-06-17 19:32:01 UTC
List:
ruby-core #76064
Issue #12501 has been reported by Yu Zhang.
----------------------------------------
Bug #12501: Assignment to local variable itself doesn't occur an error
https://bugs.ruby-lang.org/issues/12501
* Author: Yu Zhang
* Status: Open
* Priority: Normal
* Assignee:
* ruby -v: 2.3.0
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
For example:
~~~
a = b # => undefined local variable or method `b' for main:Object (NameError)
~~~
but
~~~
a = a # => nil
a = a.merge({}) # => undefined method `merge' for nil:NilClass (NoMethodError)
~~~
The `a` after `=` is an undefined local variable, I think it should raise a `NameError`, but it only returns a nil value.
Is this a feature or bug?
--
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>