@@ -11,7 +11,7 @@ import config.Config
1111import config .Printers .{constr , subtyping , gadts , noPrinter }
1212import TypeErasure .{erasedLub , erasedGlb }
1313import TypeApplications ._
14- import Variances .variancesConform
14+ import Variances .{ Variance , variancesConform }
1515import Constants .Constant
1616import transform .TypeUtils ._
1717import transform .SymUtils ._
@@ -1952,7 +1952,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
19521952 val t2 = distributeAnd(tp2, tp1)
19531953 if (t2.exists) t2
19541954 else if (isErased) erasedGlb(tp1, tp2, isJava = false )
1955- else liftIfHK(tp1, tp2, op, original)
1955+ else liftIfHK(tp1, tp2, op, original, _ | _ )
19561956 }
19571957 }
19581958
@@ -2000,7 +2000,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
20002000 val t2 = distributeOr(tp2, tp1)
20012001 if (t2.exists) t2
20022002 else if (isErased) erasedLub(tp1, tp2)
2003- else liftIfHK(tp1, tp2, OrType (_, _), _ | _)
2003+ else liftIfHK(tp1, tp2, OrType (_, _), _ | _, _ & _ )
20042004 }
20052005 }
20062006
@@ -2009,7 +2009,8 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
20092009 *
20102010 * [X1, ..., Xn] -> op(tp1[X1, ..., Xn], tp2[X1, ..., Xn])
20112011 */
2012- private def liftIfHK (tp1 : Type , tp2 : Type , op : (Type , Type ) => Type , original : (Type , Type ) => Type ) = {
2012+ private def liftIfHK (tp1 : Type , tp2 : Type ,
2013+ op : (Type , Type ) => Type , original : (Type , Type ) => Type , combineVariance : (Variance , Variance ) => Variance ) = {
20132014 val tparams1 = tp1.typeParams
20142015 val tparams2 = tp2.typeParams
20152016 def applied (tp : Type ) = tp.appliedTo(tp.typeParams.map(_.paramInfoAsSeenFrom(tp)))
@@ -2020,9 +2021,12 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
20202021 original(applied(tp1), tp2)
20212022 else if (tparams1.hasSameLengthAs(tparams2))
20222023 HKTypeLambda (
2023- paramNames = HKTypeLambda .syntheticParamNames(tparams1.length).lazyZip(tparams1).lazyZip(tparams2)
2024- .map((pname, tparam1, tparam2) =>
2025- pname.withVariance((tparam1.paramVarianceSign + tparam2.paramVarianceSign) / 2 )))(
2024+ paramNames = HKTypeLambda .syntheticParamNames(tparams1.length),
2025+ variances =
2026+ if tp1.isVariantLambda && tp2.isVariantLambda then
2027+ tparams1.lazyZip(tparams2).map((p1, p2) => combineVariance(p1.paramVariance, p2.paramVariance))
2028+ else Nil
2029+ )(
20262030 paramInfosExp = tl => tparams1.lazyZip(tparams2).map((tparam1, tparam2) =>
20272031 tl.integrate(tparams1, tparam1.paramInfoAsSeenFrom(tp1)).bounds &
20282032 tl.integrate(tparams2, tparam2.paramInfoAsSeenFrom(tp2)).bounds),
0 commit comments