File tree Expand file tree Collapse file tree 3 files changed +12
-8
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 3 files changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -1002,15 +1002,17 @@ class Namer { typer: Typer =>
10021002 }
10031003 sym.info = dummyInfo2
10041004
1005- // If this type does not have type parameters itself, treat the parameters
1006- // of a type lambda on the RHS as non-variant. E.g.
1007- // type F <: [X] =>> G and type F[X] <: G
1005+ // Treat the parameters of an upper type lambda bound on the RHS as non-variant.
1006+ // E.g. type F <: [X] =>> G and type F[X] <: G
10081007 // are treated alike.
10091008 def addVariances (tp : Type ): Type = tp match
1010- case tp @ TypeBounds (lo, hi) =>
1011- tp.derivedTypeBounds(addVariances(lo), addVariances(hi))
1012- case tp : HKTypeLambda if tparamSyms.isEmpty && ! tp.isDeclaredVarianceLambda =>
1013- tp.withVariances(tp.paramNames.map(alwaysInvariant))
1009+ case tp : TypeBounds =>
1010+ def recur (tp : Type ): Type = tp match
1011+ case tp : HKTypeLambda if ! tp.isDeclaredVarianceLambda =>
1012+ tp.withVariances(tp.paramNames.map(alwaysInvariant))
1013+ .derivedLambdaType(resType = recur(tp.resType))
1014+ case tp => tp
1015+ tp.derivedTypeBounds(tp.lo, recur(tp.hi))
10141016 case _ =>
10151017 tp
10161018
Original file line number Diff line number Diff line change 11case class Contra [- A ](f : A => Int )
22
33case class Covarify [+ F <: ([A ] =>> Any ), + A ](fa : F [A ]) // error: covariant type A occurs in invariant position in type F[A] of value fa
4+ case class Covarify2 [+ F [+ X ] <: ([A ] =>> Any ), + A ](fa : F [Int ][A ]) // error: covariant type A occurs in invariant position in type F[A] of value fa
5+ case class Covarify3 [+ F <: [X ] =>> [A ] =>> Any , + A ](fa : F [Int ][A ]) // error: covariant type A occurs in invariant position in type F[A] of value fa
46
57@ main def main = {
68 val x = Covarify [Contra , Int ](Contra [Int ](_ + 5 ))
You can’t perform that action at this time.
0 commit comments