scala/scala3

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

Open

#18,631 创建于 2023年10月2日

在 GitHub 查看
 (10 评论) (0 反应) (0 负责人)Scala (1,159 fork)batch import
area:documentationgood first issueitype:enhancement

仓库指标

Star
 (6,247 star)
PR 合并指标
 (平均合并 18天 14小时) (30 天内合并 133 个 PR)

描述

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

贡献者指南