summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/typechecker/Typers.scala
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@epfl.ch>2011-10-20 22:29:20 +0000
committerAdriaan Moors <adriaan.moors@epfl.ch>2011-10-20 22:29:20 +0000
commit8a9fd64129926eea35f7dca181242855f14e153f (patch)
tree4defd18749999b6e14d9fba1ccc5e1507b453a64 /src/compiler/scala/tools/nsc/typechecker/Typers.scala
parent891a6e466b1b22b93c091d590178f7e5410f608e (diff)
downloadscala-8a9fd64129926eea35f7dca181242855f14e153f.tar.gz
scala-8a9fd64129926eea35f7dca181242855f14e153f.tar.bz2
scala-8a9fd64129926eea35f7dca181242855f14e153f.zip
virtpatmat, hidden behind -Yvirtpatmat
at least one imminent TODO: undo hardwired generation of if/then/else, and decide based on type whether to call flatMap/orElse or inline those methods from Option review by extempore
Diffstat (limited to 'src/compiler/scala/tools/nsc/typechecker/Typers.scala')
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index c2dd1ba6a2..13cd299fa2 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -27,7 +27,7 @@ import scala.tools.util.StringOps.{ countAsString, countElementsAsString }
* @author Martin Odersky
* @version 1.0
*/
-trait Typers extends Modes with Adaptations {
+trait Typers extends Modes with Adaptations with PatMatVirtualiser {
self: Analyzer =>
import global._
@@ -3280,11 +3280,23 @@ trait Typers extends Modes with Adaptations {
} else {
val selector1 = checkDead(typed(selector, EXPRmode | BYVALmode, WildcardType))
var cases1 = typedCases(tree, cases, selector1.tpe.widen, pt)
- val (owntype, needAdapt) = ptOrLub(cases1 map (_.tpe))
- if (needAdapt) {
- cases1 = cases1 map (adaptCase(_, owntype))
+
+ if (phase.id > currentRun.typerPhase.id || !opt.virtPatmat) {
+ val (owntype, needAdapt) = ptOrLub(cases1 map (_.tpe))
+ if (needAdapt) {
+ cases1 = cases1 map (adaptCase(_, owntype))
+ }
+ treeCopy.Match(tree, selector1, cases1) setType owntype
+ } else { // don't run translator after typers (see comments in PatMatVirtualiser)
+ def repackExistential(tp: Type): Type = existentialAbstraction((tp filter {t => t.typeSymbol.isExistentiallyBound}) map (_.typeSymbol), tp)
+ val (owntype0, needAdapt) = ptOrLub(cases1 map (x => repackExistential(x.tpe)))
+ val owntype = elimAnonymousClass(owntype0)
+ if (needAdapt) cases1 = cases1 map (adaptCase(_, owntype))
+
+ val translated = (new MatchTranslator(this)).X(treeCopy.Match(tree, selector1, cases1), owntype)
+
+ typed1(translated, mode, WildcardType) setType owntype // TODO: get rid of setType owntype -- it should all typecheck
}
- treeCopy.Match(tree, selector1, cases1) setType owntype
}
}