Skip to content

Variance error in copy method #20039

Open
@Krever

Description

@Krever

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:

  • The variance error disappears when handleError method is removed.
  • It compiles in Scala 2.
  • The error points to the generated copy method
  • I don't see why it would be a contravariant position

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:typerarea:varianceIssues related to covariance & contravariance.itype:bugstat:fixed in nextThe issue was fixed in Next and only still applies to LTS.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions