Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

strictEquality == works even if the given CanEqual fails #13728

soronpo started this conversation in General Discussion
Discussion options

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"

You must be logged in to vote

Replies: 2 comments

Comment options

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 ==

You must be logged in to vote
0 replies
Comment options

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
You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Converted from issue

This discussion was converted from issue #13725 on October 11, 2021 09:34.

AltStyle によって変換されたページ (->オリジナル) /