scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.84k stars 1.05k forks source link

Variance error in copy method #20039

Open Krever opened 6 months ago

Krever commented 6 months ago

Compiler version

3.3.3

Minimized code

sealed trait WIO[+Err, +Out] {

  def handleError[Err1,Out1 >: Out, ErrIn >: Err](
      f: ErrIn => WIO[Err1, Out1]
  ): WIO[Err1, Out1] = HandleError(f)

}

case class HandleError[+ErrOut, +Out, ErrIn](handleError: ErrIn => WIO[ErrOut, Out]) extends WIO[ErrOut, Out]

Output

The below output is taken from scastie execution

covariant type Out occurs in contravariant position in type [ErrOut, Out, ErrIn]: (Any => Playground.WIO[Any, Out]) =>
  Playground.WIO[Any, Out] of method copy$default$1

Expectation

I believe this is a bug due to the following reason:

Sorry for the poor issue title, I couldn't think of a better one.

som-snytt commented 6 months ago

it does not yet compile in 3.4.0 but does compile in 3.4.2-RC1-bin-SNAPSHOT-git-a36849f