Runtime: Default hashcode for struct with double or float field is wrong

Created on 24 Feb 2018  路  3Comments  路  Source: dotnet/runtime

Repro:

using System;

struct StructWithDoubleField
{
    public double value;
}

class My {

    static void Main() {
        StructWithDoubleField s1;
        s1.value = 0.0;
        StructWithDoubleField s2;
        s2.value = -0.0;

        Console.WriteLine(s1.GetHashCode() == s2.GetHashCode() ? "PASSED" : "FAILED");
    }

}

Most helpful comment

The default GetHashCode implementation for structs should have been throw new NotSupportedException("Tomato!"); :grin:

All 3 comments

The default GetHashCode implementation for structs should have been throw new NotSupportedException("Tomato!"); :grin:

@jkotas what is the process to request porting at least the object field portion of the fix to a patch release? Given customer-reported downstream bugs such as aspnet/Mvc#7673, seems like we need this at least in 2.0.x.

/cc @davidfowl @Eilon @Petermarcu

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aggieben picture aggieben  路  3Comments

btecu picture btecu  路  3Comments

ilmax picture ilmax  路  3Comments

yahorsi picture yahorsi  路  3Comments

noahfalk picture noahfalk  路  3Comments