-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Documentation help needed: given [T]: CanEqual[T, T]
resolves CanEqual
s of different types
#18631
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
Comments
I believe that the generic given is allowing scala to find a |
for contrast
I assumed it was taking |
if I add this extra method: def doEqual[T1, T2](t1: T1, t2: T2)(using CanEqual[T1, T2]) = t1 == t2 it becomes clear that @main def run(): Unit =
{
Eq.doEqual[Test, Test2](Test.apply(1), Test2.apply(2))(
Eq.given_CanEqual_T_T[Test | Test2])
()
} |
I believe this changed since #15642, but might be wrong. However even in 3.0.0 this still compiled, just with |
I'd say this is by design because inference can always widen (EDIT: a contravariant type parameter) to make a constraint work |
Why is this "by design" only for
https://scastie.scala-lang.org/gCcmi7hgQBqu6eN9XlIySA That does not sound ok to me. |
|
Otherwise, you end up with strict equals being too strict, and not being able to compare things that should be comparable. Like how in munit, which tries to have a strict equals with |
Perhaps we should add a recommendation in the Docs (API as well) to not define a "universal" |
given [T]: CanEqual[T, T]
resolves CanEqual
s of different typesgiven [T]: CanEqual[T, T]
resolves CanEqual
s of different types
Previously, we rejected the case where a symbol of a self type selection was private if was not of the enclosing class. But that symbol could shadow a non-private symbol in a base class, so have to treat that case as well. Fixes scala#18631
Previously, we rejected the case where a symbol of a self type selection was private if was not of the enclosing class. But that symbol could shadow a non-private symbol in a base class, so have to treat that case as well. Fixes scala#18631
The commit references are spurious typos. (The test name in that commit is also a typo.) |
Compiler version: 3.3.1
Compiler option:
-language:strictEquality
The following code compiles fine. But why? Where does it finds
CanEqual[Test, Test2]
of different types?https://scastie.scala-lang.org/X6boEpObQXee5uhESbviuQ
Thanks
The text was updated successfully, but these errors were encountered: