@@ -94,14 +94,15 @@ object PatternMatcher {
9494 */
9595 private val initializer = MutableSymbolMap [Tree ]()
9696
97- private def newVar (rhs : Tree , flags : FlagSet ): TermSymbol =
97+ private def newVar (rhs : Tree , flags : FlagSet , tpe : Type ): TermSymbol =
9898 newSymbol(ctx.owner, PatMatStdBinderName .fresh(), Synthetic | Case | flags,
99- sanitize(rhs. tpe), coord = rhs.span)
99+ sanitize(tpe), coord = rhs.span)
100100 // TODO: Drop Case once we use everywhere else `isPatmatGenerated`.
101101
102102 /** The plan `let x = rhs in body(x)` where `x` is a fresh variable */
103- private def letAbstract (rhs : Tree )(body : Symbol => Plan ): Plan = {
104- val vble = newVar(rhs, EmptyFlags )
103+ private def letAbstract (rhs : Tree , tpe : Type = NoType )(body : Symbol => Plan ): Plan = {
104+ val declTpe = if tpe.exists then tpe else rhs.tpe
105+ val vble = newVar(rhs, EmptyFlags , declTpe)
105106 initializer(vble) = rhs
106107 LetPlan (vble, body(vble))
107108 }
@@ -223,6 +224,13 @@ object PatternMatcher {
223224 /** Plan for matching `scrutinee` symbol against `tree` pattern */
224225 private def patternPlan (scrutinee : Symbol , tree : Tree , onSuccess : Plan ): Plan = {
225226
227+ extension (tree : Tree ) def avoidPatBoundType (): Type =
228+ tree.tpe.widen match
229+ case tref : TypeRef if tref.symbol.isPatternBound =>
230+ defn.AnyType
231+ case _ =>
232+ tree.tpe
233+
226234 /** Plan for matching `selectors` against argument patterns `args` */
227235 def matchArgsPlan (selectors : List [Tree ], args : List [Tree ], onSuccess : Plan ): Plan = {
228236 /* For a case with arguments that have some test on them such as
@@ -243,7 +251,7 @@ object PatternMatcher {
243251 */
244252 def matchArgsSelectorsPlan (selectors : List [Tree ], syms : List [Symbol ]): Plan =
245253 selectors match {
246- case selector :: selectors1 => letAbstract(selector)(sym => matchArgsSelectorsPlan(selectors1, sym :: syms))
254+ case selector :: selectors1 => letAbstract(selector, selector.avoidPatBoundType() )(sym => matchArgsSelectorsPlan(selectors1, sym :: syms))
247255 case Nil => matchArgsPatternPlan(args, syms.reverse)
248256 }
249257 def matchArgsPatternPlan (args : List [Tree ], syms : List [Symbol ]): Plan =
0 commit comments