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