[ruby-core:77924] [Ruby trunk Bug#12897][Rejected] Hash failed to recognize the existed key and send not found when using Vector as key
From:
ruby-core@...
Date:
2016-11-04 17:18:53 UTC
List:
ruby-core #77924
Issue #12897 has been updated by Marc-Andre Lafortune.
Status changed from Open to Rejected
This is not a bug. `Hash#[]` uses `eql?` and not `==` to match keys.
0 == 0.0 # => true
0.eql? 0.0 # => false
{0 => 42}[0.0] # => nil
{0.0 => 42}[0.0] # => 42
----------------------------------------
Bug #12897: Hash failed to recognize the existed key and send not found when using Vector as key
https://bugs.ruby-lang.org/issues/12897#change-61238
* Author: 智偉 姚
* Status: Rejected
* Priority: Normal
* Assignee:
* ruby -v: ruby 2.0.0p648 (2015-12-16 revision 53162) [x86_64-linux]
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
When I was using Vector as the key to the Hash, Hash sometimes failed to recognize the key and send nil, while the key-value pair actually existed.
Example as followed:
irb(main):002:0> require"matrix"
=> true
irb(main):003:0> Vector[0.1E1, 0.2E1, 0.0] == Vector[0.1E1, 0.2E1, 0]
=> true
irb(main):004:0> p = { Vector[0.1E1, 0.2E1, 0.0] => 1}
=> {Vector[1.0, 2.0, 0.0]=>1}
irb(main):005:0> p.has_key?(Vector[0.1E1, 0.2E1, 0])
=> false
irb(main):006:0> Vector[0.1E1, 0.2E1, 0] == Vector[0.1E1, 0.2E1, 0.0]
=> true
As you can see, the key is corrected recognized, but the Hash could not recognize it.
--
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>