diff options
author | Martin Odersky <odersky@gmail.com> | 2011-11-22 18:07:51 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2011-11-22 18:07:51 +0000 |
commit | ac031789039d421186567cf3b9a484957e6e5f8e (patch) | |
tree | 5145e02ea0debdf1cd2a467ad8568e2813a03c56 | |
parent | cd696035896fd82c622687107ec4b70cf3f3298e (diff) | |
download | scala-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)
-rw-r--r-- | src/compiler/scala/reflect/internal/StdNames.scala | 1 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/TreeGen.scala | 12 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/UnCurry.scala | 9 | ||||
-rwxr-xr-x | test/disabled/pos/t1545.scala (renamed from test/files/pos/t1545.scala) | 2 |
4 files changed, 22 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() = { diff --git a/test/files/pos/t1545.scala b/test/disabled/pos/t1545.scala index 51df606da3..4c5908b8a1 100755 --- a/test/files/pos/t1545.scala +++ b/test/disabled/pos/t1545.scala @@ -1,3 +1,5 @@ +// According to the spec this code should not be legal. +// Disabling for now. object Main extends App { case class Foo (field : Option[String]) |