scala/scala3

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

オープン

#18,631 opened on 2023/10/02

 (10 件のコメント) (0 件のリアクション) (0 人の担当者)Scala (1,159 件のフォーク)batch import
area:documentationgood first issueitype:enhancement

Repository metrics

Stars
 (6,247 個のスター)
PR merge metrics
 (平均マージ 18d 14h) (30d で 133 merged PRs)

説明

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

コントリビューターガイド