Unity started shipping a newer compiler which comes with some new warnings. I noticed one today that flags this situation:
IInterface thing1 = GetSomeInterfaceRef();
// Thing2 implements IInterface, and overloads operator==
Thing2 thing2 = GetThing2();
bool thingsAreTheSame = thing1 == thing2;Since the overloaded operator is statically resolved, and defined as
bool operator==(Thing2 a, Thing2 b), it won't be used and fall back
to reference equality instead.
This is a useful warning, because I've seen this trip people up.
Except it's practically useless in Unity code because its base
UnityEngine.Object class overloads operator==, and you wind up with
mostly false positives. You can avoid lots of false positives if you
comb through all of these and replace x == y with
object.ReferenceEquals(x, y). Yes, I did that, and it made me
grumpy and prompted me to write this gist.