aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-05-12 17:52:15 +0200
committerMartin Odersky <odersky@gmail.com>2016-05-23 16:11:45 +0200
commit3c1a87b0e4bd7f163485ec3aeb028848ce4c2e43 (patch)
tree7b70bf53bd3914e18f1f70014da019940681eca8
parentcae7b7828934f5b31bfc6b506ca2b5bac8dcde05 (diff)
downloaddotty-3c1a87b0e4bd7f163485ec3aeb028848ce4c2e43.tar.gz
dotty-3c1a87b0e4bd7f163485ec3aeb028848ce4c2e43.tar.bz2
dotty-3c1a87b0e4bd7f163485ec3aeb028848ce4c2e43.zip
Move eqAny to Predef
-rw-r--r--src/dotty/DottyPredef.scala8
-rw-r--r--src/dotty/tools/dotc/core/Definitions.scala6
-rw-r--r--src/dotty/tools/dotc/typer/Implicits.scala4
-rw-r--r--src/scala/Eq.scala11
4 files changed, 14 insertions, 15 deletions
diff --git a/src/dotty/DottyPredef.scala b/src/dotty/DottyPredef.scala
index 9e1f2102c..cd90c4882 100644
--- a/src/dotty/DottyPredef.scala
+++ b/src/dotty/DottyPredef.scala
@@ -12,6 +12,14 @@ object DottyPredef {
implicit def arrayTag[T](implicit ctag: ClassTag[T]): ClassTag[Array[T]] =
ctag.wrap
+ /** A fall-back implicit to compare values of any types.
+ * The compiler will restrict implicit instances of `eqAny`. An instance
+ * `eqAny[T, U]` is _valid_ if `T <: U` or `U <: T` or both `T` and `U` are
+ * Eq-free. A type `S` is Eq-free if there is no implicit instance of `Eq[S, S]`.
+ * An implicit search will fail instead of returning an invalid `eqAny` instance.
+ */
+ implicit def eqAny[L, R]: Eq[L, R] = Eq
+
implicit def eqNumber : Eq[Number, Number] = Eq
implicit def eqString : Eq[String, String] = Eq
diff --git a/src/dotty/tools/dotc/core/Definitions.scala b/src/dotty/tools/dotc/core/Definitions.scala
index d9f3432bd..bcc986755 100644
--- a/src/dotty/tools/dotc/core/Definitions.scala
+++ b/src/dotty/tools/dotc/core/Definitions.scala
@@ -244,6 +244,9 @@ class Definitions {
lazy val DottyPredefModuleRef = ctx.requiredModuleRef("dotty.DottyPredef")
def DottyPredefModule(implicit ctx: Context) = DottyPredefModuleRef.symbol
+
+ def Predef_eqAny(implicit ctx: Context) = DottyPredefModule.requiredMethod(nme.eqAny)
+
lazy val DottyArraysModuleRef = ctx.requiredModuleRef("dotty.runtime.Arrays")
def DottyArraysModule(implicit ctx: Context) = DottyArraysModuleRef.symbol
def newGenericArrayMethod(implicit ctx: Context) = DottyArraysModule.requiredMethod("newGenericArray")
@@ -431,9 +434,6 @@ class Definitions {
lazy val EqType = ctx.requiredClassRef("scala.Eq")
def EqClass(implicit ctx: Context) = EqType.symbol.asClass
- def EqModule(implicit ctx: Context) = EqClass.companionModule
-
- def Eq_eqAny(implicit ctx: Context) = EqModule.requiredMethod(nme.eqAny)
// Annotation base classes
lazy val AnnotationType = ctx.requiredClassRef("scala.annotation.Annotation")
diff --git a/src/dotty/tools/dotc/typer/Implicits.scala b/src/dotty/tools/dotc/typer/Implicits.scala
index a5d415d97..38ac709be 100644
--- a/src/dotty/tools/dotc/typer/Implicits.scala
+++ b/src/dotty/tools/dotc/typer/Implicits.scala
@@ -595,7 +595,7 @@ trait Implicits { self: Typer =>
// Does there exist an implicit value of type `Eq[tp, tp]`?
def hasEq(tp: Type): Boolean =
new ImplicitSearch(defn.EqType.appliedTo(tp, tp), EmptyTree, pos).bestImplicit match {
- case result: SearchSuccess => result.ref.symbol != defn.Eq_eqAny
+ case result: SearchSuccess => result.ref.symbol != defn.Predef_eqAny
case result: AmbiguousImplicits => true
case _ => false
}
@@ -613,7 +613,7 @@ trait Implicits { self: Typer =>
}
else generated1 match {
case TypeApply(fn, targs @ (arg1 :: arg2 :: Nil))
- if fn.symbol == defn.Eq_eqAny && !validEqAnyArgs(arg1.tpe, arg2.tpe) =>
+ if fn.symbol == defn.Predef_eqAny && !validEqAnyArgs(arg1.tpe, arg2.tpe) =>
nonMatchingImplicit(ref)
case _ =>
SearchSuccess(generated1, ref, ctx.typerState)
diff --git a/src/scala/Eq.scala b/src/scala/Eq.scala
index 8275ecee8..99d03bbb6 100644
--- a/src/scala/Eq.scala
+++ b/src/scala/Eq.scala
@@ -10,14 +10,5 @@ sealed trait Eq[-L, -R]
* can also be used as a value that's compatible with
* any instance of `Eq`.
*/
-object Eq extends Eq[Any, Any] {
-
- /** A fall-back implicit to compare values of any types.
- * The compiler will restrict implicit instances of `eqAny`. An instance
- * `eqAny[T, U]` is _valid_ if `T <: U` or `U <: T` or both `T` and `U` are
- * Eq-free. A type `S` is Eq-free if there is no implicit instance of `Eq[S, S]`.
- * An implicit search will fail instead of returning an invalid `eqAny` instance.
- */
- implicit def eqAny[L, R]: Eq[L, R] = Eq
-}
+object Eq extends Eq[Any, Any]