Proper equality comparison for bound callable references represented as reflection objects

(including references to property accessors).
This commit is contained in:
Dmitry Petrov
2016-11-23 16:24:30 +03:00
parent 3dd0c9d1c7
commit 5879e201cd
14 changed files with 148 additions and 21 deletions
@@ -40,7 +40,7 @@ public abstract class CallableReference implements KCallable {
private KCallable reflected;
protected final Object receiver$0;
private static final Object NO_RECEIVER = new Object();
public static final Object NO_RECEIVER = new Object();
public CallableReference() {
this(NO_RECEIVER);
@@ -52,6 +52,10 @@ public abstract class CallableReference implements KCallable {
protected abstract KCallable computeReflected();
public Object getBoundReceiver() {
return receiver$0;
}
public KCallable compute() {
KCallable result = reflected;
if (result == null) {
@@ -80,7 +80,7 @@ public class FunctionReference extends CallableReference implements FunctionImpl
return getOwner().equals(other.getOwner()) &&
getName().equals(other.getName()) &&
getSignature().equals(other.getSignature()) &&
Intrinsics.areEqual(receiver$0, other.receiver$0);
Intrinsics.areEqual(getBoundReceiver(), other.getBoundReceiver());
}
if (obj instanceof KFunction) {
return obj.equals(compute());
@@ -51,7 +51,7 @@ public abstract class PropertyReference extends CallableReference implements KPr
return getOwner().equals(other.getOwner()) &&
getName().equals(other.getName()) &&
getSignature().equals(other.getSignature()) &&
Intrinsics.areEqual(receiver$0, other.receiver$0);
Intrinsics.areEqual(getBoundReceiver(), other.getBoundReceiver());
}
if (obj instanceof KProperty) {
return obj.equals(compute());