Project

General

Profile

Actions

Bug #9231

closed

The value of [].hash is equal to the value of false.hash

Added by phasis68 (Heesob Park) almost 11 years ago. Updated almost 11 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.1.0dev (2013-12-09 trunk 44080) [x64-mswin64_120]
[ruby-core:58993]

Description

I found that [].hash == false.hash.
And the combinations of each elements also have the same value.
Is this an intended behavior?

C:\Users\phasis>irb
irb(main):001:0> [].hash
=> 1336528015
irb(main):002:0> false.hash
=> 1336528015

irb(main):003:0> [false,false].hash
=> -1570892633
irb(main):004:0> [false,[]].hash
=> -1570892633
irb(main):005:0> [[],false].hash
=> -1570892633
irb(main):006:0> [[],[]].hash
=> -1570892633

irb(main):008:0> {false=>false}.hash
=> -539662806
irb(main):009:0> {[]=>[]}.hash
=> -539662806
irb(main):010:0> {[]=>false}.hash
=> -539662806
irb(main):011:0> {false=>[]}.hash
=> -539662806

Actions #1

Updated by nobu (Nobuyoshi Nakada) almost 11 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r44125.
Heesob, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


array.c, hash.c: add salt

  • array.c (rb_ary_hash): add salt to differentiate false and empty
    array. [ruby-core:58993] [Bug #9231]
  • hash.c (rb_any_hash, rb_hash_hash): ditto.
Actions

Also available in: Atom PDF

Like0
Like0