Skip to content

Commit 3c1a87b

Browse files
committed
Move eqAny to Predef
1 parent cae7b78 commit 3c1a87b

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

src/dotty/DottyPredef.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ object DottyPredef {
1212
implicit def arrayTag[T](implicit ctag: ClassTag[T]): ClassTag[Array[T]] =
1313
ctag.wrap
1414

15+
/** A fall-back implicit to compare values of any types.
16+
* The compiler will restrict implicit instances of `eqAny`. An instance
17+
* `eqAny[T, U]` is _valid_ if `T <: U` or `U <: T` or both `T` and `U` are
18+
* Eq-free. A type `S` is Eq-free if there is no implicit instance of `Eq[S, S]`.
19+
* An implicit search will fail instead of returning an invalid `eqAny` instance.
20+
*/
21+
implicit def eqAny[L, R]: Eq[L, R] = Eq
22+
1523
implicit def eqNumber : Eq[Number, Number] = Eq
1624
implicit def eqString : Eq[String, String] = Eq
1725

src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ class Definitions {
244244

245245
lazy val DottyPredefModuleRef = ctx.requiredModuleRef("dotty.DottyPredef")
246246
def DottyPredefModule(implicit ctx: Context) = DottyPredefModuleRef.symbol
247+
248+
def Predef_eqAny(implicit ctx: Context) = DottyPredefModule.requiredMethod(nme.eqAny)
249+
247250
lazy val DottyArraysModuleRef = ctx.requiredModuleRef("dotty.runtime.Arrays")
248251
def DottyArraysModule(implicit ctx: Context) = DottyArraysModuleRef.symbol
249252
def newGenericArrayMethod(implicit ctx: Context) = DottyArraysModule.requiredMethod("newGenericArray")
@@ -431,9 +434,6 @@ class Definitions {
431434

432435
lazy val EqType = ctx.requiredClassRef("scala.Eq")
433436
def EqClass(implicit ctx: Context) = EqType.symbol.asClass
434-
def EqModule(implicit ctx: Context) = EqClass.companionModule
435-
436-
def Eq_eqAny(implicit ctx: Context) = EqModule.requiredMethod(nme.eqAny)
437437

438438
// Annotation base classes
439439
lazy val AnnotationType = ctx.requiredClassRef("scala.annotation.Annotation")

src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ trait Implicits { self: Typer =>
595595
// Does there exist an implicit value of type `Eq[tp, tp]`?
596596
def hasEq(tp: Type): Boolean =
597597
new ImplicitSearch(defn.EqType.appliedTo(tp, tp), EmptyTree, pos).bestImplicit match {
598-
case result: SearchSuccess => result.ref.symbol != defn.Eq_eqAny
598+
case result: SearchSuccess => result.ref.symbol != defn.Predef_eqAny
599599
case result: AmbiguousImplicits => true
600600
case _ => false
601601
}
@@ -613,7 +613,7 @@ trait Implicits { self: Typer =>
613613
}
614614
else generated1 match {
615615
case TypeApply(fn, targs @ (arg1 :: arg2 :: Nil))
616-
if fn.symbol == defn.Eq_eqAny && !validEqAnyArgs(arg1.tpe, arg2.tpe) =>
616+
if fn.symbol == defn.Predef_eqAny && !validEqAnyArgs(arg1.tpe, arg2.tpe) =>
617617
nonMatchingImplicit(ref)
618618
case _ =>
619619
SearchSuccess(generated1, ref, ctx.typerState)

src/scala/Eq.scala

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,5 @@ sealed trait Eq[-L, -R]
1010
* can also be used as a value that's compatible with
1111
* any instance of `Eq`.
1212
*/
13-
object Eq extends Eq[Any, Any] {
14-
15-
/** A fall-back implicit to compare values of any types.
16-
* The compiler will restrict implicit instances of `eqAny`. An instance
17-
* `eqAny[T, U]` is _valid_ if `T <: U` or `U <: T` or both `T` and `U` are
18-
* Eq-free. A type `S` is Eq-free if there is no implicit instance of `Eq[S, S]`.
19-
* An implicit search will fail instead of returning an invalid `eqAny` instance.
20-
*/
21-
implicit def eqAny[L, R]: Eq[L, R] = Eq
22-
}
13+
object Eq extends Eq[Any, Any]
2314

0 commit comments

Comments
 (0)