-
Notifications
You must be signed in to change notification settings - Fork 21
Closed
scala/scala
#8545Labels
fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)has PR
Milestone
Description
Example:
case class Holder[F[+_, +_]](v: F[Int, Int]) {
def asWiden[F2[+x, +y] >: F[x, y]]: F2[Int, Int] = v
}
object example extends App {
println(Holder[Right](Right(5)).asWiden[Either])
}
Produces error:
Error:(4, 16) covariant type x occurs in contravariant position in type [+x, +y] >: F[x,y] of type F2
def asWiden[F2[+x, +y] >: F[x, y]]: F2[Int, Int] = v
^
Expected it to succeed, as the expression does not appear unsound!
Writing it as F2[+x, +y] >: F[_, _]
passes the variance checker, but the expression using the function fails to typecheck:
Error:(7, 99) type arguments [Either] do not conform to method asWiden's type parameter bounds [F2[+x, +y] >: Right[_, _]]
def res0 = Holder[Right](Right(5)).asWiden[Either] ^
Scala version 2.13.1
Metadata
Metadata
Assignees
Labels
fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)has PR