@@ -45,7 +45,12 @@ class PatternMatcher extends MiniPhaseTransform {
4545object PatternMatcher {
4646 import ast .tpd ._
4747
48- final val selfCheck = true // debug option, if on we check that no case gets generated twice
48+ final val selfCheck = false // debug option, if on we check that no case gets generated twice
49+
50+ /** Was symbol generated by pattern matcher? */
51+ def isPatmatGenerated (sym : Symbol )(implicit ctx : Context ): Boolean =
52+ sym.is(Synthetic ) &&
53+ (sym.name.is(PatMatStdBinderName ) || sym.name.is(PatMatCaseName ))
4954
5055 /** The pattern matching translator.
5156 * Its general structure is a pipeline:
@@ -77,6 +82,7 @@ object PatternMatcher {
7782 private def newVar (rhs : Tree , flags : FlagSet ): TermSymbol =
7883 ctx.newSymbol(ctx.owner, PatMatStdBinderName .fresh(), Synthetic | Case | flags,
7984 sanitize(rhs.tpe), coord = rhs.pos)
85+ // TODO: Drop Case once we use everywhere else `isPatmatGenerated`.
8086
8187 /** The plan `let x = rhs in body(x)` where `x` is a fresh variable */
8288 private def letAbstract (rhs : Tree )(body : Symbol => Plan ): Plan = {
@@ -93,11 +99,6 @@ object PatternMatcher {
9399 LabelledPlan (label, body(CallPlan (label, Nil )), Nil )
94100 }
95101
96- /** Was symbol generated by pattern matcher? */
97- private def isPatmatGenerated (sym : Symbol ) =
98- sym.is(Synthetic ) &&
99- (sym.is(Label ) || sym.name.is(PatMatStdBinderName ))
100-
101102 /** Test whether a type refers to a pattern-generated variable */
102103 private val refersToInternal = new TypeAccumulator [Boolean ] {
103104 def apply (x : Boolean , tp : Type ) =
@@ -687,7 +688,11 @@ object PatternMatcher {
687688 val LetPlan (topSym, _) = plan
688689
689690 def toDrop (sym : Symbol ) =
690- initializer.contains(sym) && isPatmatGenerated(sym) && refCount(sym) <= 1 && sym != topSym
691+ initializer.contains(sym) &&
692+ isPatmatGenerated(sym) &&
693+ refCount(sym) <= 1 &&
694+ sym != topSym &&
695+ isPureExpr(initializer(sym))
691696
692697 object Inliner extends PlanTransform {
693698 override val treeMap = new TreeMap {
0 commit comments