Skip to content

Commit e3bad2e

Browse files
committed
Fix #2020: Only the first parameters of a case class are caseaccessors
Only the parameters in the first parameter list of a case class should get the `CaseAccessor` flag. Fixes #2020.
1 parent 8a826ee commit e3bad2e

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,13 @@ object desugar {
469469
val originalVparams = constr1.vparamss.toIterator.flatten
470470
val tparamAccessors = derivedTparams.map(_.withMods(originalTparams.next.mods))
471471
val caseAccessor = if (isCaseClass) CaseAccessor else EmptyFlags
472-
val vparamAccessors = derivedVparamss.flatten.map(_.withMods(originalVparams.next.mods | caseAccessor))
472+
val vparamAccessors = derivedVparamss match {
473+
case first :: rest =>
474+
first.map(_.withMods(originalVparams.next.mods | caseAccessor)) ++
475+
rest.flatten.map(_.withMods(originalVparams.next.mods))
476+
case _ =>
477+
Nil
478+
}
473479
cpy.TypeDef(cdef)(
474480
name = className,
475481
rhs = cpy.Template(impl)(constr, parents1, self1,

tests/run/i2020.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
object Test {
2+
3+
case class Foo(x: Int)(y: Int)
4+
5+
def main(args: Array[String]) =
6+
assert(Foo(1)(1) == Foo(1)(2))
7+
8+
}

0 commit comments

Comments
 (0)