Skip to content

Fix #8649: Remove @uncheckedVariance on defaults #9184

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
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -550,13 +550,9 @@ object desugar {
// def _1: T1 = this.p1
// ...
// def _N: TN = this.pN
// def copy(p1: T1 = p1: @uncheckedVariance, ...,
// pN: TN = pN: @uncheckedVariance)(moreParams) =
// def copy(p1: T1 = p1, ...,
// pN: TN = pN)(moreParams) =
// new C[...](p1, ..., pN)(moreParams)
//
// Note: copy default parameters need @uncheckedVariance; see
// neg/t1843-variances.scala for a test case. The test would give
// two errors without @uncheckedVariance, one of them spurious.
val caseClassMeths = {
def syntheticProperty(name: TermName, tpt: Tree, rhs: Tree) =
DefDef(name, Nil, Nil, tpt, rhs).withMods(synthetic)
Expand All @@ -573,10 +569,8 @@ object desugar {
})
if (mods.is(Abstract) || hasRepeatedParam) Nil // cannot have default arguments for repeated parameters, hence copy method is not issued
else {
def copyDefault(vparam: ValDef) =
makeAnnotated("scala.annotation.unchecked.uncheckedVariance", refOfDef(vparam))
val copyFirstParams = derivedVparamss.head.map(vparam =>
cpy.ValDef(vparam)(rhs = copyDefault(vparam)))
cpy.ValDef(vparam)(rhs = refOfDef(vparam)))
val copyRestParamss = derivedVparamss.tail.nestedMap(vparam =>
cpy.ValDef(vparam)(rhs = EmptyTree))
DefDef(nme.copy, derivedTparams, copyFirstParams :: copyRestParamss, TypeTree(), creatorExpr)
Expand Down
32 changes: 32 additions & 0 deletions tests/pos/8649.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// This is crazy:
type Get0 = OK[Int, Unit]
def get0: Handler[Get0] = IO[Unit]()

case class HandlerAlt[A](value: Handler[A])

type Handler[API] = handler.Go[API]

case class IO[A]()
case class OK[A, B]()

object handler:
// Starter for Handler reduction:
type Go[API] = API match
case _ =>
HandlerSingle[API]

type HandlerSingle[X] = X match
case OK[_, response] =>
IO[response]

object Minimized {
case class HandlerAlt[A](value: M2[A])

type M1[X] = X match {
case _ => M2[X]
}

type M2[X] = X match {
case Int => String
}
}