diff options
author | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-02-09 12:12:19 +0100 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-02-17 14:19:02 +0100 |
commit | 0643b79165e1ad524c5c99a9a7664fdf356d121a (patch) | |
tree | c85ab1bb1b8d30212877e705be462a24d86d39aa /src/compiler | |
parent | a57ac60dbb115b90ca1ccc9944199bf3e82d517d (diff) | |
download | scala-0643b79165e1ad524c5c99a9a7664fdf356d121a.tar.gz scala-0643b79165e1ad524c5c99a9a7664fdf356d121a.tar.bz2 scala-0643b79165e1ad524c5c99a9a7664fdf356d121a.zip |
[vpm] generate proper isDefinedAt for switches
don't consider the matcherror-throwing catch-all case (generated by virtpatmat) a default case
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/UnCurry.scala | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala index c26b19b04d..94e562b82f 100644 --- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala +++ b/src/compiler/scala/tools/nsc/transform/UnCurry.scala @@ -348,11 +348,18 @@ abstract class UnCurry extends InfoTransform substTree(idaBlock.duplicate) // duplicate on block as a whole to ensure valdefs are properly cloned and substed } + def dropMatchErrorCatchAll(cases: List[CaseDef]): List[CaseDef] = + if (!opt.virtPatmat) cases + else cases filter { + case CaseDef(pat, EmptyTree, Throw(Apply(Select(New(exTpt), nme.CONSTRUCTOR), _))) if (treeInfo.isWildcardArg(pat) && (exTpt.tpe.typeSymbol eq MatchErrorClass)) => false + case CaseDef(pat, guard, body) => true + } + DefDef(m, (fun.body: @unchecked) match { case Match(selector, cases) => - dupMatch(selector, cases) + dupMatch(selector, dropMatchErrorCatchAll(cases)) case Block((vd: ValDef) :: Nil, Match(selector, cases)) => // can't factor this out using an extractor due to bugs in the old pattern matcher - dupMatch(selector, cases, m => Block(List(vd), m)) + dupMatch(selector, dropMatchErrorCatchAll(cases), m => Block(List(vd), m)) // virtpatmat -- TODO: find a better way to keep this in synch with the code generated by patmatvirtualizer case Apply(Apply(TypeApply(Select(tgt, nme.runOrElse), targs), args_scrut), args_pm) if opt.virtPatmat => object noOne extends Transformer { |