aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-10-23 10:58:06 +0200
committerMartin Odersky <odersky@gmail.com>2015-10-23 10:58:06 +0200
commit0a386a85da9c6df97bf2cb6627e1f905af17c123 (patch)
tree383f74b08c9a337302b8dc50dfe2359badcbd879 /src
parent9cb35429fc2c52f5d243b9c9d29739df1ff5967a (diff)
downloaddotty-0a386a85da9c6df97bf2cb6627e1f905af17c123.tar.gz
dotty-0a386a85da9c6df97bf2cb6627e1f905af17c123.tar.bz2
dotty-0a386a85da9c6df97bf2cb6627e1f905af17c123.zip
Only replace intersections of constants with Nothing
Diffstat (limited to 'src')
-rw-r--r--src/dotty/tools/dotc/core/TypeComparer.scala14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala
index f7fd145ad..3a5922e90 100644
--- a/src/dotty/tools/dotc/core/TypeComparer.scala
+++ b/src/dotty/tools/dotc/core/TypeComparer.scala
@@ -780,11 +780,17 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
val t2 = mergeIfSub(tp2, tp1)
if (t2.exists) t2
else tp1 match {
- case tp1: SingletonType =>
+ case tp1: ConstantType =>
tp2 match {
- case tp2: SingletonType =>
- // Make use of the fact that the intersection of two singleton
- // types which are not subtypes of each other is empty.
+ case tp2: ConstantType =>
+ // Make use of the fact that the intersection of two constant types
+ // types which are not subtypes of each other is known to be empty.
+ // Note: The same does not apply to singleton types in general.
+ // E.g. we could have a pattern match against `x.type & y.type`
+ // which might succeed if `x` and `y` happen to be the same ref
+ // at run time. It would not work to replace that with `Nothing`.
+ // However, maybe we can still apply the replacement to
+ // types which are not explicitly written.
defn.NothingType
case _ => andType(tp1, tp2)
}