aboutsummaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-12-19 16:18:07 +0100
committerFelix Mulder <felix.mulder@gmail.com>2016-12-19 16:18:07 +0100
commitaaf0a630c9d24b628e5ec115f963ead8c9aaa3f8 (patch)
tree9c0a2404a5bcc6f64a5c6a874559d5fe29d65e92 /compiler
parent51cfebe23ea081b297642a24b1208c174e4e0ca2 (diff)
downloaddotty-aaf0a630c9d24b628e5ec115f963ead8c9aaa3f8.tar.gz
dotty-aaf0a630c9d24b628e5ec115f963ead8c9aaa3f8.tar.bz2
dotty-aaf0a630c9d24b628e5ec115f963ead8c9aaa3f8.zip
Move `eqNullable` check to `assumedCanEqual`
Diffstat (limited to 'compiler')
-rw-r--r--compiler/src/dotty/tools/dotc/typer/Implicits.scala32
1 files changed, 12 insertions, 20 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala
index e17a2b7b6..303953e73 100644
--- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala
+++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala
@@ -542,6 +542,15 @@ trait Implicits { self: Typer =>
}
private def assumedCanEqual(ltp: Type, rtp: Type)(implicit ctx: Context) = {
+ def eqNullable: Boolean = {
+ val other =
+ if (ltp.isRef(defn.NullClass)) rtp
+ else if (rtp.isRef(defn.NullClass)) ltp
+ else NoType
+
+ (other ne NoType) && !other.derivesFrom(defn.AnyValClass)
+ }
+
val lift = new TypeMap {
def apply(t: Type) = t match {
case t: TypeRef =>
@@ -553,7 +562,7 @@ trait Implicits { self: Typer =>
if (variance > 0) mapOver(t) else t
}
}
- ltp.isError || rtp.isError || ltp <:< lift(rtp) || rtp <:< lift(ltp)
+ ltp.isError || rtp.isError || ltp <:< lift(rtp) || rtp <:< lift(ltp) || eqNullable
}
/** Check that equality tests between types `ltp` and `rtp` make sense */
@@ -670,27 +679,10 @@ trait Implicits { self: Typer =>
case _ => false
}
- // Is Eq[X, Null] or Eq[Null, X] where !(X <:< AnyVal)?
- def eqNullable(tp1: Type, tp2: Type): Boolean = {
- val other =
- if (tp1.stripTypeVar eq defn.NullType) tp2
- else if (tp2.stripTypeVar eq defn.NullType) tp1
- else NoType
-
- (other ne NoType) && !other.derivesFrom(defn.AnyValClass)
- }
-
def validEqAnyArgs(tp1: Type, tp2: Type) = {
List(tp1, tp2).foreach(fullyDefinedType(_, "eqAny argument", pos))
- def invalidEqAny = {
- implicits.println(i"invalid eqAny[$tp1, $tp2]")
- false
- }
-
- assumedCanEqual(tp1, tp2) ||
- !hasEq(tp1) && !hasEq(tp2) ||
- eqNullable(tp1, tp2) ||
- invalidEqAny
+ assumedCanEqual(tp1, tp2) || !hasEq(tp1) && !hasEq(tp2) ||
+ { implicits.println(i"invalid eqAny[$tp1, $tp2]"); false }
}
if (ctx.reporter.hasErrors)
nonMatchingImplicit(ref, ctx.reporter.removeBufferedMessages)