Skip to content

Added CanEqual support#407

Open
felix-hedenstrom wants to merge 9 commits intokitlangton:mainfrom
felix-hedenstrom:can-equal-support
Open

Added CanEqual support#407
felix-hedenstrom wants to merge 9 commits intokitlangton:mainfrom
felix-hedenstrom:can-equal-support

Conversation

@felix-hedenstrom
Copy link
Contributor

At $work we are trying out multiversal equality. One of its bigger drawbacks is the need to specify a lot of CanEqual givens. Right now we are defining our own CanEqual for neotypes but it requires ugly given imports wherever we need to compare neotypes.

This PR adds a handy CanEqual given that makes it so that Neotypes will have an available CanEqual if the wrapped type has one.

@felix-hedenstrom
Copy link
Contributor Author

Link to relevant scala3 documentation https://docs.scala-lang.org/scala3/reference/contextual/multiversal-equality.html

@felix-hedenstrom
Copy link
Contributor Author

Looks like this revealed some test issues but also made me realize that this isn't a backwards compatible change as of now. Let me see if I can make it backwardscompatible.

@felix-hedenstrom
Copy link
Contributor Author

I tried adding a regression test to make sure that old equality behavior remains where the flag is not enabled, but the chimney test is still failing.

I don't have any ideas what might be causing this. Not sure how to proceed...

@felix-hedenstrom
Copy link
Contributor Author

felix-hedenstrom commented Feb 2, 2026

I think all the errors that this PR detected are actual code errors that we should fix but that went undetected since there was no CanEqual defined.

I realized that the documentation mentions why this happens

Even though canEqualAny is not declared as given, the compiler will still construct a canEqualAny instance as answer to an implicit search for the type CanEqual[L, R], unless L or R have CanEqual instances defined on them, or the language feature strictEquality is enabled.

So me defining a CanEqual removes the use of the default defined one. The PR in this form would be a breaking change (even though I think it is a very useful breaking change, since it detected multiple issues within this repo alone). I haven't worked with hybrid codebases were CanEqual is defined for some cases but the flag is not enabled so I was not aware of this outcome.

@kitlangton should I move this into a separate module, something like neotype-canequal?

@felix-hedenstrom
Copy link
Contributor Author

Hi @kitlangton. Have you had time to think about this? I would be fine making this into neotype-canequal if you think that it is appropriate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant