Skip to content

Commit ba4fee7

Browse files
committed
Stop patmat from using selector pos for Try.
It doesn't exist. Also use symbol with 'ex' name as selector for exceptions
1 parent 049bcb5 commit ba4fee7

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/dotty/tools/dotc/transform/PatternMatcher.scala

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
5050

5151
override def transformMatch(tree: Match)(implicit ctx: Context, info: TransformerInfo): Tree = {
5252
val translated = new Translator()(ctx).translator.translateMatch(tree)
53-
translated.ensureConforms(tree.tpe)
53+
54+
Typed(translated.ensureConforms(tree.tpe), TypeTree(tree.tpe))
5455
}
5556

5657
class Translator(implicit ctx: Context) {
@@ -1136,7 +1137,13 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
11361137
* this could probably optimized... (but note that the matchStrategy must be solved for each nested patternmatch)
11371138
*/
11381139
def translateMatch(match_ : Match): Tree = {
1139-
val Match(selector, cases) = match_
1140+
val Match(sel, cases) = match_
1141+
1142+
val selectorTp = elimAnonymousClass(sel.tpe.widen/*withoutAnnotations*/)
1143+
1144+
val selectorSym =
1145+
if (sel ne ExceptionHandlerSel) freshSym(sel.pos, selectorTp, "selector")
1146+
else freshSym(match_.pos, defn.ThrowableType, "ex")
11401147

11411148
val (nonSyntheticCases, defaultOverride) = cases match {
11421149
case init :+ last if isSyntheticDefaultCase(last) => (init, Some(((scrut: Symbol) => last.body)))
@@ -1155,23 +1162,20 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
11551162

11561163
//val start = if (Statistics.canEnable) Statistics.startTimer(patmatNanos) else null
11571164

1158-
val selectorTp = elimAnonymousClass(selector.tpe.widen/*withoutAnnotations*/)
1159-
11601165
// when one of the internal cps-type-state annotations is present, strip all CPS annotations
11611166
///val origPt = removeCPSFromPt(match_.tpe)
11621167
// relevant test cases: pos/existentials-harmful.scala, pos/gadt-gilles.scala, pos/t2683.scala, pos/virtpatmat_exist4.scala
11631168
// pt is the skolemized version
11641169
val pt = match_.tpe.widen //repeatedToSeq(origPt)
11651170

11661171
// val packedPt = repeatedToSeq(typer.packedType(match_, context.owner))
1167-
val selectorSym = freshSym(selector.pos, selectorTp, "selector")
11681172
selectorSym.setFlag(Flags.SyntheticCase)
11691173

11701174
// pt = Any* occurs when compiling test/files/pos/annotDepMethType.scala with -Xexperimental
1171-
val combined = combineCases(selector, selectorSym, nonSyntheticCases map translateCase(selectorSym, pt), pt, ctx.owner, defaultOverride)
1175+
val combined = combineCases(sel, selectorSym, nonSyntheticCases map translateCase(selectorSym, pt), pt, ctx.owner, defaultOverride)
11721176

11731177
// if (Statistics.canEnable) Statistics.stopTimer(patmatNanos, start)
1174-
Block(List(ValDef(selectorSym,selector)), combined)
1178+
Block(List(ValDef(selectorSym, sel)), combined)
11751179
}
11761180

11771181
// return list of typed CaseDefs that are supported by the backend (typed/bind/wildcard)

0 commit comments

Comments
 (0)