Skip to content

Fix #5419: explicit result types for _N in case classes #5424

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

Merged
merged 1 commit into from
Nov 11, 2018
Merged
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
13 changes: 7 additions & 6 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,9 @@ object desugar {
lazy val creatorExpr = New(classTypeRef, constrVparamss nestedMap refOfDef)

// Methods to add to a case class C[..](p1: T1, ..., pN: Tn)(moreParams)
// def _1 = this.p1
// def _1: T1 = this.p1
// ...
// def _N = this.pN
// def _N: TN = this.pN
// def copy(p1: T1 = p1: @uncheckedVariance, ...,
// pN: TN = pN: @uncheckedVariance)(moreParams) =
// new C[...](p1, ..., pN)(moreParams)
Expand All @@ -442,12 +442,13 @@ object desugar {
// 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, rhs: Tree) =
DefDef(name, Nil, Nil, TypeTree(), rhs).withMods(synthetic)
def syntheticProperty(name: TermName, tpt: Tree, rhs: Tree) =
DefDef(name, Nil, Nil, tpt, rhs).withMods(synthetic)
def productElemMeths = {
val caseParams = constrVparamss.head.toArray
val caseParams = derivedVparamss.head.toArray
for (i <- 0 until arity if nme.selectorName(i) `ne` caseParams(i).name)
yield syntheticProperty(nme.selectorName(i), Select(This(EmptyTypeIdent), caseParams(i).name))
yield syntheticProperty(nme.selectorName(i), caseParams(i).tpt,
Select(This(EmptyTypeIdent), caseParams(i).name))
}
def enumTagMeths = if (isEnumCase) enumTagMeth(CaseKind.Class)._1 :: Nil else Nil
def copyMeths = {
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/t1843-variances.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

object Crash {
trait UpdateType[A]
case class StateUpdate[+A](updateType : UpdateType[A], value : A) // error // error
case class StateUpdate[+A](updateType : UpdateType[A], value : A) // error
case object IntegerUpdateType extends UpdateType[Integer]

//However this method will cause a crash
Expand Down
8 changes: 8 additions & 0 deletions tests/pos/case-getters.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
case class Foo(x: 1, y: implicit Int => Int)
object Test {
val f = Foo(1, implicit (i: Int) => i)
val fx1: 1 = f.x
val fx2: 1 = f._1
val fy1: Int = f.y(1)
val fy2: Int = f._2(1)
}