Skip to content

Commit

Permalink
Check meta-class of method objects in equals (#4918)
Browse files Browse the repository at this point in the history
In MRI, `method_eq` checks CLASS_OF method objects

```
(CLASS_OF(method) != CLASS_OF(other))
```

By this change, `TestMethod#test_eq` will be passed.
yui-knk authored and kares committed Jan 1, 2018
1 parent 278e039 commit f8fb28d
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/RubyMethod.java
Original file line number Diff line number Diff line change
@@ -162,6 +162,10 @@ public boolean equals(Object other) {
if (method instanceof ProcMethod) {
return ((ProcMethod) method).isSame(((RubyMethod) other).getMethod());
}
if (getMetaClass() != ((RubyBasicObject) other).getMetaClass()) {
return false;
}

RubyMethod otherMethod = (RubyMethod)other;
return receiver == otherMethod.receiver && originModule == otherMethod.originModule &&
( isSerialMatch(otherMethod.method) || isMethodMissingMatch(otherMethod.getMethod().getRealMethod()) );
1 change: 0 additions & 1 deletion test/mri/excludes/TestMethod.rb
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@
exclude :test_clone, "needs investigation"
exclude :test_define_method_visibility, "needs investigation"
exclude :test_define_method_with_symbol, "scope changes in define_method methods?"
exclude :test_eq, "weird logic for != when patching an object retuned from o.method, likely irrelevant"
exclude :test_gced_bmethod, "often 'Timeout::Error: execution of assert_normal_exit expired' on CI"
exclude :test_inspect, "fails since an alias-ed method does not distinguish owner and implementor module"
exclude :test_hash, "won't pass since Array#map is not a Array#collect alias as in MRI"

0 comments on commit f8fb28d

Please sign in to comment.