From ba4fee76dd5d93e52672e223633539e932ccf0b6 Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Tue, 28 Oct 2014 14:34:34 +0100 Subject: Stop patmat from using selector pos for Try. It doesn't exist. Also use symbol with 'ex' name as selector for exceptions --- src/dotty/tools/dotc/transform/PatternMatcher.scala | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/dotty/tools/dotc/transform/PatternMatcher.scala') diff --git a/src/dotty/tools/dotc/transform/PatternMatcher.scala b/src/dotty/tools/dotc/transform/PatternMatcher.scala index 8af1b4a21..6e8b58f56 100644 --- a/src/dotty/tools/dotc/transform/PatternMatcher.scala +++ b/src/dotty/tools/dotc/transform/PatternMatcher.scala @@ -50,7 +50,8 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans override def transformMatch(tree: Match)(implicit ctx: Context, info: TransformerInfo): Tree = { val translated = new Translator()(ctx).translator.translateMatch(tree) - translated.ensureConforms(tree.tpe) + + Typed(translated.ensureConforms(tree.tpe), TypeTree(tree.tpe)) } class Translator(implicit ctx: Context) { @@ -1136,7 +1137,13 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans * this could probably optimized... (but note that the matchStrategy must be solved for each nested patternmatch) */ def translateMatch(match_ : Match): Tree = { - val Match(selector, cases) = match_ + val Match(sel, cases) = match_ + + val selectorTp = elimAnonymousClass(sel.tpe.widen/*withoutAnnotations*/) + + val selectorSym = + if (sel ne ExceptionHandlerSel) freshSym(sel.pos, selectorTp, "selector") + else freshSym(match_.pos, defn.ThrowableType, "ex") val (nonSyntheticCases, defaultOverride) = cases match { case init :+ last if isSyntheticDefaultCase(last) => (init, Some(((scrut: Symbol) => last.body))) @@ -1155,8 +1162,6 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans //val start = if (Statistics.canEnable) Statistics.startTimer(patmatNanos) else null - val selectorTp = elimAnonymousClass(selector.tpe.widen/*withoutAnnotations*/) - // when one of the internal cps-type-state annotations is present, strip all CPS annotations ///val origPt = removeCPSFromPt(match_.tpe) // relevant test cases: pos/existentials-harmful.scala, pos/gadt-gilles.scala, pos/t2683.scala, pos/virtpatmat_exist4.scala @@ -1164,14 +1169,13 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans val pt = match_.tpe.widen //repeatedToSeq(origPt) // val packedPt = repeatedToSeq(typer.packedType(match_, context.owner)) - val selectorSym = freshSym(selector.pos, selectorTp, "selector") selectorSym.setFlag(Flags.SyntheticCase) // pt = Any* occurs when compiling test/files/pos/annotDepMethType.scala with -Xexperimental - val combined = combineCases(selector, selectorSym, nonSyntheticCases map translateCase(selectorSym, pt), pt, ctx.owner, defaultOverride) + val combined = combineCases(sel, selectorSym, nonSyntheticCases map translateCase(selectorSym, pt), pt, ctx.owner, defaultOverride) // if (Statistics.canEnable) Statistics.stopTimer(patmatNanos, start) - Block(List(ValDef(selectorSym,selector)), combined) + Block(List(ValDef(selectorSym, sel)), combined) } // return list of typed CaseDefs that are supported by the backend (typed/bind/wildcard) -- cgit v1.2.3