I'm trying to understand this equality behavior. The record equality test fails, but the equality test of the sole property of the records passes. Is this a bug? Or can someone explain this behavior?
type TestUnion =
| Case1
| Case2 of (int -> string)
type TestType =
{
Foo : TestUnion
}
open Microsoft.VisualStudio.TestTools.UnitTesting
[<TestClass>]
public Testing() =
let a = { Foo = Case1 }
let b = { Foo = Case1 }
[<TestMethod>]
member __.ThisFails () =
Assert.AreEqual(a, b)
[<TestMethod>]
member __.ThisPasses () =
Assert.AreEqual(a.Foo, b.Foo)
I know the reason it fails is because one of the cases is a function. If I change it to a simple value, both tests pass. But it is odd to me that a) equality fails at all because the simple case with no value is used and b) the record equality fails while the property equality passes.
Note: The record equality will fail when other simple properties are present also. IOW, the union type poisons equality for the whole record, even though the union type property tests as equal.