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