Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python] Nested type with Custom Equality gives false negative equality #3717

Closed
HLWeil opened this issue Jan 26, 2024 · 0 comments · Fixed by #3734
Closed

[Python] Nested type with Custom Equality gives false negative equality #3717

HLWeil opened this issue Jan 26, 2024 · 0 comments · Fixed by #3734
Labels

Comments

@HLWeil
Copy link

HLWeil commented Jan 26, 2024

Description

If a record type with custom equality and hashcode is included in another type, calling the equality on the outer type returns false, possibly because custom equality of inner type is not used.

Possibly related to #3674, which works like a charm now, thank you!

Repro code

test.fsx

[<CustomEquality; NoComparison>]
type X = 
    {
        ID : int 
        Name : string 
    }

    override x.GetHashCode() = x.ID

    override this.Equals(other : obj) = 
        match other with
        | :? X as other -> this.ID = other.ID
        | _ -> false

// Record type here (unlike issue #3674)
type Y = 
    {X : X}

// Should be equal according to custom equality
let x1 = {ID = 1; Name = "a"}
let x2 = {ID = 1; Name = "b"}

// Should all be equal according to custom equality of inner type
let y1 = {X = x1}
let y2 = {X = x2}
let y3 = {X = x1}



printfn $"x1=x2:{x1 = x2}" // true

printfn $"y1=y2:{y1 = y2}" // incorrectly false
printfn $"y1=y3:{y1 = y3}" // correctly true, possibly because equal by non-custom equality 

test.cmd

dotnet fable . --lang python
python test.py

Expected and actual results

Expected: Everything should be true.

Actual: Two records containing a only a record each that should be equal by custom equality still returns false

Related information

  • dotnet fable --version: 4.10.0
  • dotnet tool list/update/install: 4.10.0
  • Windows11

@Freymaurer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants