From ac031789039d421186567cf3b9a484957e6e5f8e Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 22 Nov 2011 18:07:51 +0000 Subject: 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) --- src/compiler/scala/reflect/internal/StdNames.scala | 1 + src/compiler/scala/tools/nsc/ast/TreeGen.scala | 12 ++++++++++++ src/compiler/scala/tools/nsc/transform/UnCurry.scala | 9 +++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) (limited to 'src') 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() = { -- cgit v1.2.3