@@ -5062,6 +5062,7 @@ object Types {
5062
5062
case TypeTest (tpe : Type )
5063
5063
case BaseTypeTest (classType : TypeRef , argPatterns : List [MatchTypeCasePattern ], needsConcreteScrut : Boolean )
5064
5064
case CompileTimeS (argPattern : MatchTypeCasePattern )
5065
+ case AbstractTypeConstructor (tycon : Type , argPatterns : List [MatchTypeCasePattern ])
5065
5066
5066
5067
def isTypeTest : Boolean =
5067
5068
this .isInstanceOf [TypeTest ]
@@ -5137,25 +5138,15 @@ object Types {
5137
5138
case pat @ AppliedType (tycon : TypeRef , args) if variance == 1 =>
5138
5139
val tyconSym = tycon.symbol
5139
5140
if tyconSym.isClass then
5140
- val cls = tyconSym.asClass
5141
- if cls.name.startsWith(" Tuple" ) && defn.isTupleNType(pat) then
5141
+ if tyconSym.name.startsWith(" Tuple" ) && defn.isTupleNType(pat) then
5142
5142
rec(pat.toNestedPairs, variance)
5143
5143
else
5144
- val tparams = tycon.typeParams
5145
- val argPatterns = args.zip(tparams).map { (arg, tparam) =>
5146
- rec(arg, tparam.paramVarianceSign)
5144
+ recArgPatterns(pat) { argPatterns =>
5145
+ val needsConcreteScrut = argPatterns.zip(tycon.typeParams).exists {
5146
+ (argPattern, tparam) => tparam.paramVarianceSign != 0 && argPattern.needsConcreteScrutInVariantPos
5147
+ }
5148
+ MatchTypeCasePattern .BaseTypeTest (tycon, argPatterns, needsConcreteScrut)
5147
5149
}
5148
- if argPatterns.exists(_ == null ) then
5149
- null
5150
- else
5151
- val argPatterns1 = argPatterns.asInstanceOf [List [MatchTypeCasePattern ]] // they are not null
5152
- if argPatterns1.forall(_.isTypeTest) then
5153
- MatchTypeCasePattern .TypeTest (pat)
5154
- else
5155
- val needsConcreteScrut = argPatterns1.zip(tparams).exists {
5156
- (argPattern, tparam) => tparam.paramVarianceSign != 0 && argPattern.needsConcreteScrutInVariantPos
5157
- }
5158
- MatchTypeCasePattern .BaseTypeTest (tycon, argPatterns1, needsConcreteScrut)
5159
5150
else if defn.isCompiletime_S(tyconSym) && args.sizeIs == 1 then
5160
5151
val argPattern = rec(args.head, variance)
5161
5152
if argPattern == null then
@@ -5165,12 +5156,39 @@ object Types {
5165
5156
else
5166
5157
MatchTypeCasePattern .CompileTimeS (argPattern)
5167
5158
else
5168
- null
5159
+ tycon.info match
5160
+ case _ : RealTypeBounds => recAbstractTypeConstructor(pat)
5161
+ case _ => null
5162
+
5163
+ case pat @ AppliedType (tycon : TypeParamRef , _) if variance == 1 =>
5164
+ recAbstractTypeConstructor(pat)
5169
5165
5170
5166
case _ =>
5171
5167
MatchTypeCasePattern .TypeTest (pat)
5172
5168
end rec
5173
5169
5170
+ def recAbstractTypeConstructor (pat : AppliedType ): MatchTypeCasePattern | Null =
5171
+ recArgPatterns(pat) { argPatterns =>
5172
+ MatchTypeCasePattern .AbstractTypeConstructor (pat.tycon, argPatterns)
5173
+ }
5174
+ end recAbstractTypeConstructor
5175
+
5176
+ def recArgPatterns (pat : AppliedType )(whenNotTypeTest : List [MatchTypeCasePattern ] => MatchTypeCasePattern | Null ): MatchTypeCasePattern | Null =
5177
+ val AppliedType (tycon, args) = pat
5178
+ val tparams = tycon.typeParams
5179
+ val argPatterns = args.zip(tparams).map { (arg, tparam) =>
5180
+ rec(arg, tparam.paramVarianceSign)
5181
+ }
5182
+ if argPatterns.exists(_ == null ) then
5183
+ null
5184
+ else
5185
+ val argPatterns1 = argPatterns.asInstanceOf [List [MatchTypeCasePattern ]] // they are not null
5186
+ if argPatterns1.forall(_.isTypeTest) then
5187
+ MatchTypeCasePattern .TypeTest (pat)
5188
+ else
5189
+ whenNotTypeTest(argPatterns1)
5190
+ end recArgPatterns
5191
+
5174
5192
val result = rec(pat, variance = 1 )
5175
5193
if typeParamRefsAccountedFor == caseLambda.paramNames.size then result
5176
5194
else null
0 commit comments