@@ -4417,10 +4417,12 @@ object Types {
44174417
44184418 case tp : LambdaType =>
44194419 def mapOverLambda = {
4420- variance = - variance
4420+ val restpe = tp.resultType
4421+ val saved = variance
4422+ variance = if (defn.MatchCase .isInstance(restpe)) 0 else - variance
44214423 val ptypes1 = tp.paramInfos.mapConserve(this ).asInstanceOf [List [tp.PInfo ]]
4422- variance = - variance
4423- derivedLambdaType(tp)(ptypes1, this (tp.resultType ))
4424+ variance = saved
4425+ derivedLambdaType(tp)(ptypes1, this (restpe ))
44244426 }
44254427 mapOverLambda
44264428
@@ -4440,7 +4442,9 @@ object Types {
44404442 derivedOrType(tp, this (tp.tp1), this (tp.tp2))
44414443
44424444 case tp : MatchType =>
4443- derivedMatchType(tp, this (tp.bound), this (tp.scrutinee), tp.cases.mapConserve(this ))
4445+ val bound1 = this (tp.bound)
4446+ val scrut1 = atVariance(0 )(this (tp.scrutinee))
4447+ derivedMatchType(tp, bound1, scrut1, tp.cases.mapConserve(this ))
44444448
44454449 case tp : SkolemType =>
44464450 derivedSkolemType(tp, this (tp.info))
@@ -4804,10 +4808,12 @@ object Types {
48044808 case _ : BoundType | _ : ThisType => x
48054809
48064810 case tp : LambdaType =>
4807- variance = - variance
4811+ val restpe = tp.resultType
4812+ val saved = variance
4813+ variance = if (defn.MatchCase .isInstance(restpe)) 0 else - variance
48084814 val y = foldOver(x, tp.paramInfos)
4809- variance = - variance
4810- this (y, tp.resultType )
4815+ variance = saved
4816+ this (y, restpe )
48114817
48124818 case tp : TermRef =>
48134819 if (stopAtStatic && tp.currentSymbol.isStatic || (tp.prefix `eq` NoPrefix )) x
@@ -4835,7 +4841,9 @@ object Types {
48354841 this (this (x, tp.tp1), tp.tp2)
48364842
48374843 case tp : MatchType =>
4838- foldOver(this (this (x, tp.bound), tp.scrutinee), tp.cases)
4844+ val x1 = this (x, tp.bound)
4845+ val x2 = atVariance(0 )(this (x1, tp.scrutinee))
4846+ foldOver(x2, tp.cases)
48394847
48404848 case AnnotatedType (underlying, annot) =>
48414849 this (applyToAnnot(x, annot), underlying)
0 commit comments