Skip to content

Commit a7530b4

Browse files
oderskysmarter
authored andcommitted
Also fix variances of curried bound parameters
Requires updating effpi to use explicit kinding, todo: disallow non-explicit kinding.
1 parent 1d34c39 commit a7530b4

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff 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

tests/neg/i9061.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
case class Contra[-A](f: A => Int)
22

33
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
46

57
@main def main = {
68
val x = Covarify[Contra, Int](Contra[Int](_ + 5))

0 commit comments

Comments
 (0)