scala/scala3

Documentation help needed: `given [T]: CanEqual[T, T]` resolves `CanEqual`s of different types

Open

#18.631 aperta il 2 ott 2023

Vedi su GitHub
 (10 commenti) (0 reazioni) (0 assegnatari)Scala (1159 fork)batch import
area:documentationgood first issueitype:enhancement

Metriche repository

Star
 (6247 star)
Metriche merge PR
 (Merge medio 18g 14h) (133 PR mergiate in 30 g)

Descrizione

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?

case class Test(i: Int)
case class Test2(i: Int)

object Eq:
  given [T]: CanEqual[T, T] = CanEqual.derived

  @main def run(): Unit =
    Test(1) == Test2(2)
    ()

https://scastie.scala-lang.org/X6boEpObQXee5uhESbviuQ

Thanks

Guida contributor