Bug #9381

2.1.0 Regression. Hash lookup with #hash and #eql?

Added by Nick S over 1 year ago. Updated 3 days ago.

[ruby-core:59638]
Status:Closed
Priority:Normal
Assignee:Nobuyoshi Nakada
ruby -v:ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux] Backport:1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: REQUIRED, 2.2: REQUIRED

Description

Ruby 2.1.0 won't fetch objects when the lookup key overrides #hash and #eql?.
This is a regression as it works as expected in ruby 1.8, 1.9 and 2.0.

class Wrapper
  def initialize(obj)
    @obj = obj
  end

  def method_missing(symbol, *args, &block)
    @obj.__send__(symbol, *args, &block)
  end

  def hash
    @obj.hash
  end

  def eql?(other)
    @obj.eql?(other)
  end
end

hash = { 5 => "LOOKUP SUCCEEDED" }

# Prints "LOOKUP SUCCEEDED" on RUBY < 2.1.0. Fails on RUBY 2.1.0.
p hash[Wrapper.new(5)]

Associated revisions

Revision 44525
Added by Nobuyoshi Nakada over 1 year ago

object.c: hash value from objid with salt

  • hash.c (rb_objid_hash): return hash value from object ID with a salt, extract from rb_any_hash().
  • object.c (rb_obj_hash): return same value as rb_any_hash(). fix r44125. [Bug #9381]

Revision 44525
Added by Nobuyoshi Nakada over 1 year ago

object.c: hash value from objid with salt

  • hash.c (rb_objid_hash): return hash value from object ID with a salt, extract from rb_any_hash().
  • object.c (rb_obj_hash): return same value as rb_any_hash(). fix r44125. [Bug #9381]

Revision 51423
Added by Nobuyoshi Nakada 3 days ago

test_hash.rb: add assertions

  • test/ruby/test_hash.rb (test_wrapper_of_special_const): test other special obejcts. [Bug #9381]

Revision 51425
Added by Nobuyoshi Nakada 3 days ago

hash.c: fix float hash

  • hash.c (rb_any_hash): fix Float hash. rb_dbl_hash() returns a Fixnum, but not a long. [Bug #9381]

Revision 51426
Added by Nobuyoshi Nakada 3 days ago

hash.c: fix symbol hash

  • hash.c (rb_sym_hash): return same value as rb_any_hash() of Symbol. [Bug #9381]

History

#1 Updated by Nobuyoshi Nakada over 1 year ago

  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: UNKNOWN to 1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: REQUIRED
  • Description updated (diff)
  • Status changed from Open to Assigned
  • Assignee set to Nobuyoshi Nakada
  • Target version set to current: 2.2.0

#2 Updated by Nobuyoshi Nakada over 1 year ago

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

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


object.c: hash value from objid with salt

  • hash.c (rb_objid_hash): return hash value from object ID with a salt, extract from rb_any_hash().
  • object.c (rb_obj_hash): return same value as rb_any_hash(). fix r44125. [Bug #9381]

#3 Updated by Yui NARUSE over 1 year ago

  • Backport changed from 1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: REQUIRED to 1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: DONE

#4 Updated by Nobuyoshi Nakada over 1 year ago

  • Description updated (diff)

#5 Updated by Tomoyuki Chikanaga 3 days ago

  • Backport changed from 1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: DONE to 1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: REQUIRED, 2.2: REQUIRED

I re-fill Backport field for r51425. I'm not sure if this is bugfix or feature change though.

Also available in: Atom PDF