Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dwijnand opened this issue Apr 29, 2021 · 1 comment · Fixed by #12275
Closed

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

dwijnand opened this issue Apr 29, 2021 · 1 comment · Fixed by #12275
Milestone

Comments

@dwijnand
Copy link
Member

dwijnand commented Apr 29, 2021

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)...

@smarter
Copy link
Member

smarter commented Apr 29, 2021

I believe this doesn't happen in Scala 2 with scala/scala@fb38e47, which was addressing scala/bug#2382.

That change in Scala 2 is unsound in general, cf 5b46ac2

Did that get removed with #9909?

Looks like that's what you're hitting here yeah, we strip @uncheckedVariance from the inferred types but it turns out we need it for the default getter inferred type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants