summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2011-11-22 18:07:51 +0000
committerMartin Odersky <odersky@gmail.com>2011-11-22 18:07:51 +0000
commitac031789039d421186567cf3b9a484957e6e5f8e (patch)
tree5145e02ea0debdf1cd2a467ad8568e2813a03c56 /src
parentcd696035896fd82c622687107ec4b70cf3f3298e (diff)
downloadscala-ac031789039d421186567cf3b9a484957e6e5f8e.tar.gz
scala-ac031789039d421186567cf3b9a484957e6e5f8e.tar.bz2
scala-ac031789039d421186567cf3b9a484957e6e5f8e.zip
Compiler part of fast orElse.
"According to the spec this code should not be legal. Disabling for now." Need to come back and either make it work or (more likely) make nsc reject the test)
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/reflect/internal/StdNames.scala1
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreeGen.scala12
-rw-r--r--src/compiler/scala/tools/nsc/transform/UnCurry.scala9
3 files changed, 20 insertions, 2 deletions
diff --git a/src/compiler/scala/reflect/internal/StdNames.scala b/src/compiler/scala/reflect/internal/StdNames.scala
index 2fd5f58f3e..59d42b933f 100644
--- a/src/compiler/scala/reflect/internal/StdNames.scala
+++ b/src/compiler/scala/reflect/internal/StdNames.scala
@@ -250,6 +250,7 @@ trait StdNames extends /*reflect.generic.StdNames with*/ NameManglers { self: Sy
val lift_ : NameType = "lift"
val main: NameType = "main"
val map: NameType = "map"
+ val missingCase: NameType = "missingCase"
val ne: NameType = "ne"
val newArray: NameType = "newArray"
val next: NameType = "next"
diff --git a/src/compiler/scala/tools/nsc/ast/TreeGen.scala b/src/compiler/scala/tools/nsc/ast/TreeGen.scala
index 5ba7465928..0dc3b1fffd 100644
--- a/src/compiler/scala/tools/nsc/ast/TreeGen.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreeGen.scala
@@ -47,6 +47,18 @@ abstract class TreeGen extends reflect.internal.TreeGen {
case _ => tree
}
+ def withDefaultCase(matchExpr: Tree, defaultAction: Tree/*scrutinee*/ => Tree): Tree = matchExpr match {
+ case Match(scrutinee, cases) =>
+ if (cases exists treeInfo.isDefaultCase) matchExpr
+ else {
+ val defaultCase = CaseDef(Ident(nme.WILDCARD), EmptyTree, defaultAction(scrutinee))
+ Match(scrutinee, cases :+ defaultCase)
+ }
+ case _ =>
+ matchExpr
+ // [Martin] Adriaan: please fill in virtpatmat transformation here
+ }
+
def mkCached(cvar: Symbol, expr: Tree): Tree = {
val cvarRef = mkUnattributedRef(cvar)
Block(
diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
index 50ebb2b3a5..a15badb4fe 100644
--- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala
+++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
@@ -264,8 +264,13 @@ abstract class UnCurry extends InfoTransform
fun.vparams foreach (_.symbol.owner = applyMethod)
new ChangeOwnerTraverser(fun.symbol, applyMethod) traverse fun.body
- def applyMethodDef() = {
- val body = if (isPartial) gen.mkUncheckedMatch(fun.body) else fun.body
+
+ def missingCaseCall(scrutinee: Tree): Tree = Apply(Select(This(anonClass), nme.missingCase), List(scrutinee))
+
+ def applyMethodDef() = scala.tools.nsc.util.trace("pf "){
+ val body =
+ if (isPartial) gen.mkUncheckedMatch(gen.withDefaultCase(fun.body, missingCaseCall))
+ else fun.body
DefDef(Modifiers(FINAL), nme.apply, Nil, List(fun.vparams), TypeTree(restpe), body) setSymbol applyMethod
}
def isDefinedAtMethodDef() = {