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

Custom Comparator sometimes not detected in the GUI #8505

Closed
radeusgd opened this issue Dec 9, 2023 · 3 comments
Closed

Custom Comparator sometimes not detected in the GUI #8505

radeusgd opened this issue Dec 9, 2023 · 3 comments
Assignees
Labels

Comments

@radeusgd
Copy link
Member

radeusgd commented Dec 9, 2023

I have tried using the GUI with a custom comparator and it behaves... weird.

Let's use the following code for my repro:

from Standard.Base import all
from Standard.Table import all

type My_Type
    Value x

    score self = -self.x

    to_display_text self = self.to_text

type My_Comparator
    hash x = Nothing
    compare x y = Ordering.compare x.score y.score

Comparable.from (_ : My_Type) = My_Comparator

main =
    v = [My_Type.Value 1, My_Type.Value 3, My_Type.Value 2]
    vs = v.sort
    
    t = Table.new [["X", v]]
    

    c = Comparable.from v.first

    IO.println v
    IO.println vs
    IO.println c
    t.print

When run in CLI, all runs fine - the vector and Table get sorted fine.

When opened in GUI, at first it also seems OK.

comparator-interactive.mp4

However, once I delete the original order_by node and add it again. After some attempts - it starts failing with Incomparable_Values.
It is as if Table.order_by seems to be no longer resolving the Comparable.from I defined for My_Type, and so it is falling back to Default_Comparator and yielding the Incomparable_Values because of that.

Curiously, after running into this error, I tried computing Comparable.from v.first again and the second computation indeed shows the Default_Comparator instead of My_Comparator like the old one.

image

@JaroslavTulach
Copy link
Member

@radeusgd, can you please check whether the behavior still present in recent releases? I am not aware of any fixes related to this problem, but there have been hundreds of small changes that may change the behavior somehow. Thank you. Reopen if the faulty behavior persists.

@JaroslavTulach JaroslavTulach closed this as not planned Won't fix, can't repro, duplicate, stale Sep 23, 2024
@github-project-automation github-project-automation bot moved this from 📤 Backlog to 🟢 Accepted in Issues Board Sep 23, 2024
@radeusgd
Copy link
Member Author

OK.

I tried updating the example to the new changes (e.g. the fix that enforces the type of value returned from Comparable.from conversion). I can no longer reproduce the problem.

image

@JaroslavTulach
Copy link
Member

Thank you Radek for taking the burden of reproducing the issue away from my shoulder. I am glad to hear it works now.

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

No branches or pull requests

3 participants