@@ -94,14 +94,15 @@ object PatternMatcher {
94
94
*/
95
95
private val initializer = MutableSymbolMap [Tree ]()
96
96
97
- private def newVar (rhs : Tree , flags : FlagSet ): TermSymbol =
97
+ private def newVar (rhs : Tree , flags : FlagSet , tpe : Type ): TermSymbol =
98
98
newSymbol(ctx.owner, PatMatStdBinderName .fresh(), Synthetic | Case | flags,
99
- sanitize(rhs. tpe), coord = rhs.span)
99
+ sanitize(tpe), coord = rhs.span)
100
100
// TODO: Drop Case once we use everywhere else `isPatmatGenerated`.
101
101
102
102
/** 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)
105
106
initializer(vble) = rhs
106
107
LetPlan (vble, body(vble))
107
108
}
@@ -223,6 +224,13 @@ object PatternMatcher {
223
224
/** Plan for matching `scrutinee` symbol against `tree` pattern */
224
225
private def patternPlan (scrutinee : Symbol , tree : Tree , onSuccess : Plan ): Plan = {
225
226
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
+
226
234
/** Plan for matching `selectors` against argument patterns `args` */
227
235
def matchArgsPlan (selectors : List [Tree ], args : List [Tree ], onSuccess : Plan ): Plan = {
228
236
/* For a case with arguments that have some test on them such as
@@ -243,7 +251,7 @@ object PatternMatcher {
243
251
*/
244
252
def matchArgsSelectorsPlan (selectors : List [Tree ], syms : List [Symbol ]): Plan =
245
253
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))
247
255
case Nil => matchArgsPatternPlan(args, syms.reverse)
248
256
}
249
257
def matchArgsPatternPlan (args : List [Tree ], syms : List [Symbol ]): Plan =
0 commit comments