Skip to content

Incorrect widening of covariant type arguments passed to a polymorphic function #16406

Open
@neko-kai

Description

@neko-kai

Compiler version

3.2.1, 3.2.2-RC1, 3.3.1-RC4

Minimized code

Runnable: https://scastie.scala-lang.org/9rXw6Hg8RRSmRkk1b4NemA

case class ZIO[-R, +E, +A]()
object ZIO {
  val interrupt: ZIO[Any, Nothing, Nothing] = ZIO()
}

inline def fromHas[R, E, A](z: ZIO[R, E, A]): String = {
  compiletime.codeOf(identity(z))
}

@main def main: Unit = {
  println(fromHas(ZIO.interrupt))
}

Output

identity[ZIO[Any, Any, Any]](ZIO.interrupt)

Expectation

identity[ZIO[Any, Nothing, Nothing]](ZIO.interrupt)

Expected the type E and A parameters of ZIO.interrupt to be preserved, instead of widened all the way to Any, as in Scala 2.

Note: only covariant parameters were widened - contravariant R parameter was not widened from Any to Nothing.

This code is a minimized version of real library code in https://github.com/izumi/izumi which we're trying to port to Scala 3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions