Operator overloading is not invoked when null is involved on Android


(James Esword) #1
public class TestClass {
    public static void test() {
        NonEqObj a = null;
        EqObj b = new EqObj();

        #if COOPER
        Log.i("", $"a:{a == null}"); // print "a:true", so == overloading is not invoked
        Log.i("", $"b:{b == null}"); // print "b:false", so == overloading is not invoked
        #elif ECHOES
        System.Diagnostics.Debug.WriteLine($"a:{a == null}");  // print "a:false"
        System.Diagnostics.Debug.WriteLine($"b:{b == null}");  // print "b:true"
        #elif TOFFEE
        Foundation.NSLog($"a:{(a == null ? "true" : "false")}");  // print "a:false"
        Foundation.NSLog($"b:{(b == null ? "true" : "false")}");  // print "b:true"
        #endif
    }
}

public class NonEqObj {
    public static bool operator ==(NonEqObj a, NonEqObj b) {
        return false;
    }
}

public class EqObj{
    public static bool operator ==(EqObj a, EqObj b) {
        return true;
    }
}

Is this difference between COOPER and ECHOES/TOFFEE is by designed or a bug?


(RemObjects) #2

Thanks, logged as bugs://75954


(RemObjects) #3

bugs://75954 got closed with status fixed.