question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Strict equality CanEqual derivation fails for classes in which type argument is not used for equality

See original GitHub issue

Compiler version

Scala 3.1.1

Minimized code

import scala.language.strictEquality

case class MyClass[A](value: String)(val a: A) derives CanEqual

class Something {}

val a = MyClass[Something]("some")(new Something())
val b = MyClass[Something]("some")(new Something())

println(a == b)

Output

Values of types Playground.MyClass[Playground.Something] and Playground.MyClass[Playground.Something] cannot be compared with == or !=.
I found:

    Playground.MyClass.derived$CanEqual[Playground.Something, Playground.Something](
      /* missing */summon[CanEqual[Playground.Something, Playground.Something]]
    )

But no implicit values were found that match type CanEqual[Playground.Something, Playground.Something].

Expectation

Something is not part of case class universal equality check so it shouldn’t be part of multiversal equality constraint either

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
SimY4commented, Feb 23, 2022

@spameggo you need to enable strict quality via:

import scala.language.strictEquality

0reactions
bishaboshacommented, Feb 27, 2022

Something is not part of case class universal equality check so it shouldn’t be part of multiversal equality constraint either

ok so in this case you would want a feature change so that CanEqual derivation can analyse the equals method - this is hard in general, but making it specialised for this one use case of “if user does not define custom equals, and generic type parameter does not appear in primary constructor of case class” could be possible

Read more comments on GitHub >

github_iconTop Results From Across the Web

Strict equality (===) - JavaScript - MDN Web Docs
The strict equality (===) operator checks whether its two operands are equal, returning a Boolean result. Unlike the equality operator, the strict equality ......
Read more >
Multiversal Equality - Scala 3 - EPFL
Multiversal equality is an opt-in way to make universal equality safer. It uses a binary type class scala.CanEqual to indicate that values of...
Read more >
Multiversal Equality | Scala 3 — Book
It uses the binary type class CanEqual to indicate that values of two given types can be compared with each other. Allowing the...
Read more >
Multiversal Equality in Scala 3 | Baeldung on Scala
There are two different ways we can create CanEqual instances. 4.1. Using Type-Class Derivation.
Read more >
Groovy Language Documentation
Support classes; Class nodes; Helping the type checker; Throwing an error ... In Groovy, using == to test equality is different from using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found