aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2013-11-15 14:53:17 +0100
committerMartin Odersky <odersky@gmail.com>2013-11-15 14:53:17 +0100
commit6ca5d414e729a509a00ddc508f2abf3d24da56ca (patch)
tree8a9c2002e14a7bf22025dd12553f1b638b95bf5a
parent18da7faf93ffaefa0ee7e37211c740c1f34ddfa2 (diff)
downloaddotty-6ca5d414e729a509a00ddc508f2abf3d24da56ca.tar.gz
dotty-6ca5d414e729a509a00ddc508f2abf3d24da56ca.tar.bz2
dotty-6ca5d414e729a509a00ddc508f2abf3d24da56ca.zip
Formign lubs over widened types only.
To avoid noisy lubs such as Int(1) | Int(2) | Int(3), we impose the rule that A | B is valid only if A and B are non-singleton, widened types. This also maps Nil | Cons automatically to List, and maps None | Option automatically to Some.
-rw-r--r--src/dotty/tools/dotc/core/TypeComparer.scala7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala
index 22d0a1d0b..7b718c9c8 100644
--- a/src/dotty/tools/dotc/core/TypeComparer.scala
+++ b/src/dotty/tools/dotc/core/TypeComparer.scala
@@ -558,7 +558,12 @@ class TypeComparer(initctx: Context) extends DotClass {
else {
val t2 = mergeIfSuper(tp2, tp1)
if (t2.exists) t2
- else orType(tp1, tp2)
+ else {
+ val tp1w = tp1.widen
+ val tp2w = tp2.widen
+ if ((tp1 ne tp1w) && (tp2 ne tp2w)) lub(tp1w, tp2w)
+ else orType(tp1w, tp2w) // no need to check subtypes again
+ }
}
}