File tree 2 files changed +11
-7
lines changed
compiler/src/dotty/tools/dotc/typer
2 files changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -1002,15 +1002,17 @@ class Namer { typer: Typer =>
1002
1002
}
1003
1003
sym.info = dummyInfo2
1004
1004
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
1008
1007
// are treated alike.
1009
1008
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))
1014
1016
case _ =>
1015
1017
tp
1016
1018
Original file line number Diff line number Diff line change 1
1
case class Contra [- A ](f : A => Int )
2
2
3
3
case 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
4
6
5
7
@ main def main = {
6
8
val x = Covarify [Contra , Int ](Contra [Int ](_ + 5 ))
You can’t perform that action at this time.
0 commit comments