aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc
diff options
context:
space:
mode:
authorFelix Mulder <felix.mulder@gmail.com>2016-12-19 14:42:03 +0100
committerFelix Mulder <felix.mulder@gmail.com>2016-12-19 14:42:03 +0100
commit4c32e1b9f585777525a3f9ef5af84c992069bafd (patch)
tree3c5302f6c08b1eaf3a6d1553c6ab5bdb868dd68d /compiler/src/dotty/tools/dotc
parent59f783a981842ff8aa6299b29083cfaaece82caa (diff)
downloaddotty-4c32e1b9f585777525a3f9ef5af84c992069bafd.tar.gz
dotty-4c32e1b9f585777525a3f9ef5af84c992069bafd.tar.bz2
dotty-4c32e1b9f585777525a3f9ef5af84c992069bafd.zip
Fix #1793: allow multiversal comparisons between Null and X
Diffstat (limited to 'compiler/src/dotty/tools/dotc')
-rw-r--r--compiler/src/dotty/tools/dotc/typer/Implicits.scala22
1 files changed, 20 insertions, 2 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala
index 331533204..e17a2b7b6 100644
--- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala
+++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala
@@ -669,10 +669,28 @@ trait Implicits { self: Typer =>
case result: AmbiguousImplicits => true
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))
- assumedCanEqual(tp1, tp2) || !hasEq(tp1) && !hasEq(tp2) ||
- { implicits.println(i"invalid eqAny[$tp1, $tp2]"); false }
+ def invalidEqAny = {
+ implicits.println(i"invalid eqAny[$tp1, $tp2]")
+ false
+ }
+
+ assumedCanEqual(tp1, tp2) ||
+ !hasEq(tp1) && !hasEq(tp2) ||
+ eqNullable(tp1, tp2) ||
+ invalidEqAny
}
if (ctx.reporter.hasErrors)
nonMatchingImplicit(ref, ctx.reporter.removeBufferedMessages)