-
Notifications
You must be signed in to change notification settings - Fork 1.1k
strictEquality ==
works even if the given CanEqual
fails
#13728
-
If an implicit to the CanEqual
is introduced and fails, the ==
operation still compiles successfully.
Compiler version
v3.1.0-RC3
Minimized code
import scala.language.strictEquality class Foo() inline given CanEqual[Int, Foo] = compiletime.error("This should fail") val x = 1 == Foo()
Output
No error
Expectation
We should get the error "This should fail"
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 2 comments
-
I would not call this as a bug, the spec only requires that a definition exists in context for CanEqual[L, R]
, it is never actually evaluated by ==
Beta Was this translation helpful? Give feedback.
All reactions
-
The reference says "the definition [of a CanEqual instance] ... has no significance for runtime behavior". It "affects type checking", but doesn't make plain what that means for compiletime.
class Foo
object Foo:
@implicitNotFound("seek not to equate the Foos")
type X
//inline given X = error("seek not to equate the Foos")
inline given (X) => CanEqual[Foo, Foo] = CanEqual.derived
The error message suggests that it is trying to summon
a value, but that is misleading. TIL that implicitNotFound
is only respected when asking for the type directly, not as a condition for some other given type.
Foo.given_CanEqual_Foo_Foo(/* missing */summon[Foo.X])
Maybe instead of "instances", the reference should speak of "proofs" or "typelevel conditions".
Today's duplicate issue #22420
Workaround:
type `seek not to equate the Foos`
inline given (`seek not to equate the Foos`) => CanEqual[Foo, Foo] = CanEqual.derived
Beta Was this translation helpful? Give feedback.