summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@epfl.ch>2012-03-17 12:18:43 +0100
committerAdriaan Moors <adriaan.moors@epfl.ch>2012-03-20 19:54:21 +0100
commit8552740beda9bb07de1da329e9dc8c002090fe16 (patch)
tree745b6f0f7f7d86cdd91c3776acb0b24dd4519729
parent9e513a6d29f2cb060caf58ff5568d7955b96305a (diff)
downloadscala-8552740beda9bb07de1da329e9dc8c002090fe16.tar.gz
scala-8552740beda9bb07de1da329e9dc8c002090fe16.tar.bz2
scala-8552740beda9bb07de1da329e9dc8c002090fe16.zip
[vpm] pack types of if branches before lubbing
this way we don't end up with fresh, incompatible, skolems for every branch, but a neatly packed existential you get much nicer lubs this way -- threw in a fast path (I hope) that avoids lubbing when unnecessary (same types) since lub isn't robust enough to deal with the result of packedType, and we only really need the trivial case (S =:= T), special case it for now ... don't pack in ifs after typer, also only when virtPatmat
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index daf4ddd100..ad48712a32 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -3566,7 +3566,15 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser {
} else {
var thenp1 = typed(thenp, pt)
var elsep1 = typed(elsep, pt)
- val (owntype, needAdapt) = ptOrLub(List(thenp1.tpe, elsep1.tpe))
+
+ lazy val thenTp = packedType(thenp1, context.owner)
+ lazy val elseTp = packedType(elsep1, context.owner)
+ val (owntype, needAdapt) =
+ // virtpatmat needs more aggressive unification of skolemized types, but lub is not robust enough --> middle ground
+ if (opt.virtPatmat && !isPastTyper && thenTp =:= elseTp) (thenTp, true) // this breaks src/library/scala/collection/immutable/TrieIterator.scala
+ // TODO: skolemize (lub of packed types) when that no longer crashes on files/pos/t4070b.scala
+ else ptOrLub(List(thenp1.tpe, elsep1.tpe))
+
if (needAdapt) { //isNumericValueType(owntype)) {
thenp1 = adapt(thenp1, mode, owntype)
elsep1 = adapt(elsep1, mode, owntype)