@@ -5096,6 +5096,7 @@ object Types {
5096
5096
case TypeTest (tpe : Type )
5097
5097
case BaseTypeTest (classType : TypeRef , argPatterns : List [MatchTypeCasePattern ], needsConcreteScrut : Boolean )
5098
5098
case CompileTimeS (argPattern : MatchTypeCasePattern )
5099
+ case AbstractTypeConstructor (tycon : Type , argPatterns : List [MatchTypeCasePattern ])
5099
5100
5100
5101
def isTypeTest : Boolean =
5101
5102
this .isInstanceOf [TypeTest ]
@@ -5171,25 +5172,15 @@ object Types {
5171
5172
case pat @ AppliedType (tycon : TypeRef , args) if variance == 1 =>
5172
5173
val tyconSym = tycon.symbol
5173
5174
if tyconSym.isClass then
5174
- val cls = tyconSym.asClass
5175
- if cls.name.startsWith(" Tuple" ) && defn.isTupleNType(pat) then
5175
+ if tyconSym.name.startsWith(" Tuple" ) && defn.isTupleNType(pat) then
5176
5176
rec(pat.toNestedPairs, variance)
5177
5177
else
5178
- val tparams = tycon.typeParams
5179
- val argPatterns = args.zip(tparams).map { (arg, tparam) =>
5180
- rec(arg, tparam.paramVarianceSign)
5178
+ recArgPatterns(pat) { argPatterns =>
5179
+ val needsConcreteScrut = argPatterns.zip(tycon.typeParams).exists {
5180
+ (argPattern, tparam) => tparam.paramVarianceSign != 0 && argPattern.needsConcreteScrutInVariantPos
5181
+ }
5182
+ MatchTypeCasePattern .BaseTypeTest (tycon, argPatterns, needsConcreteScrut)
5181
5183
}
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
- val needsConcreteScrut = argPatterns1.zip(tparams).exists {
5190
- (argPattern, tparam) => tparam.paramVarianceSign != 0 && argPattern.needsConcreteScrutInVariantPos
5191
- }
5192
- MatchTypeCasePattern .BaseTypeTest (tycon, argPatterns1, needsConcreteScrut)
5193
5184
else if defn.isCompiletime_S(tyconSym) && args.sizeIs == 1 then
5194
5185
val argPattern = rec(args.head, variance)
5195
5186
if argPattern == null then
@@ -5199,12 +5190,39 @@ object Types {
5199
5190
else
5200
5191
MatchTypeCasePattern .CompileTimeS (argPattern)
5201
5192
else
5202
- null
5193
+ tycon.info match
5194
+ case _ : RealTypeBounds => recAbstractTypeConstructor(pat)
5195
+ case _ => null
5196
+
5197
+ case pat @ AppliedType (tycon : TypeParamRef , _) if variance == 1 =>
5198
+ recAbstractTypeConstructor(pat)
5203
5199
5204
5200
case _ =>
5205
5201
MatchTypeCasePattern .TypeTest (pat)
5206
5202
end rec
5207
5203
5204
+ def recAbstractTypeConstructor (pat : AppliedType ): MatchTypeCasePattern | Null =
5205
+ recArgPatterns(pat) { argPatterns =>
5206
+ MatchTypeCasePattern .AbstractTypeConstructor (pat.tycon, argPatterns)
5207
+ }
5208
+ end recAbstractTypeConstructor
5209
+
5210
+ def recArgPatterns (pat : AppliedType )(whenNotTypeTest : List [MatchTypeCasePattern ] => MatchTypeCasePattern | Null ): MatchTypeCasePattern | Null =
5211
+ val AppliedType (tycon, args) = pat
5212
+ val tparams = tycon.typeParams
5213
+ val argPatterns = args.zip(tparams).map { (arg, tparam) =>
5214
+ rec(arg, tparam.paramVarianceSign)
5215
+ }
5216
+ if argPatterns.exists(_ == null ) then
5217
+ null
5218
+ else
5219
+ val argPatterns1 = argPatterns.asInstanceOf [List [MatchTypeCasePattern ]] // they are not null
5220
+ if argPatterns1.forall(_.isTypeTest) then
5221
+ MatchTypeCasePattern .TypeTest (pat)
5222
+ else
5223
+ whenNotTypeTest(argPatterns1)
5224
+ end recArgPatterns
5225
+
5208
5226
val result = rec(pat, variance = 1 )
5209
5227
if typeParamRefsAccountedFor == caseLambda.paramNames.size then result
5210
5228
else null
0 commit comments