Skip to content

Commit f8fb28d

Browse files
yui-knkkares
authored andcommitted
Check meta-class of method objects in equals (#4918)
In MRI, `method_eq` checks CLASS_OF method objects ``` (CLASS_OF(method) != CLASS_OF(other)) ``` By this change, `TestMethod#test_eq` will be passed.
1 parent 278e039 commit f8fb28d

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

core/src/main/java/org/jruby/RubyMethod.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,10 @@ public boolean equals(Object other) {
162162
if (method instanceof ProcMethod) {
163163
return ((ProcMethod) method).isSame(((RubyMethod) other).getMethod());
164164
}
165+
if (getMetaClass() != ((RubyBasicObject) other).getMetaClass()) {
166+
return false;
167+
}
168+
165169
RubyMethod otherMethod = (RubyMethod)other;
166170
return receiver == otherMethod.receiver && originModule == otherMethod.originModule &&
167171
( isSerialMatch(otherMethod.method) || isMethodMissingMatch(otherMethod.getMethod().getRealMethod()) );

test/mri/excludes/TestMethod.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
exclude :test_clone, "needs investigation"
55
exclude :test_define_method_visibility, "needs investigation"
66
exclude :test_define_method_with_symbol, "scope changes in define_method methods?"
7-
exclude :test_eq, "weird logic for != when patching an object retuned from o.method, likely irrelevant"
87
exclude :test_gced_bmethod, "often 'Timeout::Error: execution of assert_normal_exit expired' on CI"
98
exclude :test_inspect, "fails since an alias-ed method does not distinguish owner and implementor module"
109
exclude :test_hash, "won't pass since Array#map is not a Array#collect alias as in MRI"

0 commit comments

Comments
 (0)