[Issue 10771] std.typecons.Nullable throws an exception on comparision of null values

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jan 21 14:47:55 PST 2014


https://d.puremagic.com/issues/show_bug.cgi?id=10771


Mario Kroeplin <kroeplin.d at googlemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |kroeplin.d at googlemail.com


--- Comment #5 from Mario Kroeplin <kroeplin.d at googlemail.com> 2014-01-21 14:47:47 PST ---
For Objects we no longer have to think about (lhs is rhs || lhs !is null && rhs
!is null && lhs == rhs):

bool opEquals(Object lhs, Object rhs)
{
    // If aliased to the same object or both null => equal
    if (lhs is rhs) return true;

    // If either is null => non-equal
    if (lhs is null || rhs is null) return false;

    // If same exact type => one call to method opEquals
    if (typeid(lhs) is typeid(rhs) || typeid(lhs).opEquals(typeid(rhs)))
        return lhs.opEquals(rhs);

    // General case => symmetric calls to method opEquals
    return lhs.opEquals(rhs) && rhs.opEquals(lhs);
}

(null == null) is true, and that's what it's supposed to be with Nullable!T - a
T or null.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list