Skip to content

Commit 180c8df

Browse files
authored
Merge pull request #5424 from dotty-staging/fix-impfun-case-class
Fix #5419: explicit result types for _N in case classes
2 parents c0941f3 + bbfdd1b commit 180c8df

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,9 @@ object desugar {
431431
lazy val creatorExpr = New(classTypeRef, constrVparamss nestedMap refOfDef)
432432

433433
// Methods to add to a case class C[..](p1: T1, ..., pN: Tn)(moreParams)
434-
// def _1 = this.p1
434+
// def _1: T1 = this.p1
435435
// ...
436-
// def _N = this.pN
436+
// def _N: TN = this.pN
437437
// def copy(p1: T1 = p1: @uncheckedVariance, ...,
438438
// pN: TN = pN: @uncheckedVariance)(moreParams) =
439439
// new C[...](p1, ..., pN)(moreParams)
@@ -442,12 +442,13 @@ object desugar {
442442
// neg/t1843-variances.scala for a test case. The test would give
443443
// two errors without @uncheckedVariance, one of them spurious.
444444
val caseClassMeths = {
445-
def syntheticProperty(name: TermName, rhs: Tree) =
446-
DefDef(name, Nil, Nil, TypeTree(), rhs).withMods(synthetic)
445+
def syntheticProperty(name: TermName, tpt: Tree, rhs: Tree) =
446+
DefDef(name, Nil, Nil, tpt, rhs).withMods(synthetic)
447447
def productElemMeths = {
448-
val caseParams = constrVparamss.head.toArray
448+
val caseParams = derivedVparamss.head.toArray
449449
for (i <- 0 until arity if nme.selectorName(i) `ne` caseParams(i).name)
450-
yield syntheticProperty(nme.selectorName(i), Select(This(EmptyTypeIdent), caseParams(i).name))
450+
yield syntheticProperty(nme.selectorName(i), caseParams(i).tpt,
451+
Select(This(EmptyTypeIdent), caseParams(i).name))
451452
}
452453
def enumTagMeths = if (isEnumCase) enumTagMeth(CaseKind.Class)._1 :: Nil else Nil
453454
def copyMeths = {

tests/neg/t1843-variances.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
object Crash {
88
trait UpdateType[A]
9-
case class StateUpdate[+A](updateType : UpdateType[A], value : A) // error // error
9+
case class StateUpdate[+A](updateType : UpdateType[A], value : A) // error
1010
case object IntegerUpdateType extends UpdateType[Integer]
1111

1212
//However this method will cause a crash

tests/pos/case-getters.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
case class Foo(x: 1, y: implicit Int => Int)
2+
object Test {
3+
val f = Foo(1, implicit (i: Int) => i)
4+
val fx1: 1 = f.x
5+
val fx2: 1 = f._1
6+
val fy1: Int = f.y(1)
7+
val fy2: Int = f._2(1)
8+
}

0 commit comments

Comments
 (0)