Skip to content

ComparisonIdentity.Structural.Compare returns different values for Option wrapped types #576

@manofstick

Description

@manofstick

My regression tests for #513 have shown up the following inconsistency in existing f#:

printfn "%d" <| (ComparisonIdentity.Structural.Compare (SByte.MinValue, SByte.MaxValue))
printfn "%d" <| (ComparisonIdentity.Structural.Compare (Some SByte.MinValue, Some SByte.MaxValue))

Output

-1
-255

It is due to FSharpOption's type generic call to:

LanguagePrimitives.HashCompare.GenericComparisonWithComparerIntrinsic<T>(genericComparer, x, y);

Now I doubt if anyway is using comparers in any other way than < 0 or > 0, but they may be? #513 is a potentially breaking change because it returns -1 for the Option case - i.e. matching the primitive operation (although the affects of this breaking case, to Option comparison operations being sensitive to particular return values - is almost vanishingly small I would say..)

(The good news is that if in my regression limits Compare to (sign of Compare) then I'm getting no regression errors. I'll put my regression test up soon)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions