Skip to content

@uncheckedVariance stripped from case class's copy default getter(s) #12273

Closed
@dwijnand

Description

@dwijnand

Compiler version

3.0.0-RC3

Minimized code

import scala.annotation.unchecked.uncheckedVariance

final case class Outlet[T](out: T)
final case class SourceShape[+T](val out: Outlet[T @uncheckedVariance])

Output

-- Error: test.scala:4:29 ------------------------------------------------------
4 |final case class SourceShape[+T](val out: Outlet[T @uncheckedVariance])
  |                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |covariant type T occurs in invariant position in type [T] => Outlet[T] of method copy$default$1
1 error found

Expectation

I expect it to compile like it does for Scala 2 (2.13.5).

Notes

I believe this doesn't happen in Scala 2 with scala/scala@fb38e47, which was addressing scala/bug#2382. Did that get removed with #9909? More recently #11704 also touched this, but that shipped in 3.0.0-RC2 and I originally saw this in 3.0.0-RC1. Either way, it looks like this is accidentally breaking compilation.

Btw, this comes from cross-compiling Akka Streams to Scala 3. Potentially this can be worked around by making un-casing the case classes, hand-writing all the boilerplate. For non-copy methods you can try overloading, though that becomes difficult when you have other default arguments (which is the case in Akka Streams)...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions