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

nalywa picture nalywa  ·  3Comments

matty-hall picture matty-hall  ·  3Comments

EgorBo picture EgorBo  ·  3Comments

aggieben picture aggieben  ·  3Comments

GitAntoinee picture GitAntoinee  ·  3Comments