Skip to content

Commit

Permalink
[GR-18163] UnboundMethod#hash is the same for the same method in subc…
Browse files Browse the repository at this point in the history
…lass and superclass

PullRequest: truffleruby/3493
  • Loading branch information
andrykonchin committed Sep 28, 2022
2 parents e306ad3 + 9ae3205 commit f2d0b66
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Compatibility:
* Fix exception for `Fiddle::Handle.new` with a missing library (#2714, @eregon).
* Fix arguments implicit type conversion for `BasicObject#instance_eval`, `Module#class_eval`, `Module#module_eval`, `Module#define_method` (@andrykonchin).
* Raise `ArgumentError` unconditionally when `Proc.new` is called without a block argument (@andrykonchin).
* Fix `UnboundMethod#hash` to not depend on a module it was retrieved from (#2728, @andrykonchin).

Performance:

Expand Down
10 changes: 10 additions & 0 deletions spec/ruby/core/unboundmethod/fixtures/classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,14 @@ def overridden; end
class C < B
def overridden; end
end

module HashSpecs
class SuperClass
def foo
end
end

class SubClass < SuperClass
end
end
end
7 changes: 7 additions & 0 deletions spec/ruby/core/unboundmethod/hash_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@
to_s, inspect = Array.instance_method(:to_s), Array.instance_method(:inspect)
to_s.hash.should == inspect.hash
end

it "equals a hash of the same method in the superclass" do
foo_in_superclass = UnboundMethodSpecs::HashSpecs::SuperClass.instance_method(:foo)
foo = UnboundMethodSpecs::HashSpecs::SubClass.instance_method(:foo)

foo.hash.should == foo_in_superclass.hash
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ public abstract static class HashNode extends CoreMethodArrayArgumentsNode {
protected long hash(RubyUnboundMethod rubyMethod) {
final InternalMethod method = rubyMethod.method;
long h = getContext().getHashing(this).start(method.getDeclaringModule().hashCode());
h = Hashing.update(h, rubyMethod.origin.hashCode());
h = Hashing.update(h, MethodNodes.hashInternalMethod(method));
return Hashing.end(h);
}
Expand Down

0 comments on commit f2d0b66

Please sign in to comment.