Skip to content

Commit 403a16f

Browse files
committed
Fix #1797: Allow case class params with names _1, _2, ...
This was not possible before because it clashed with the automatically generated name of the accessor. We now allow it, by simply taking the parameter(accessor) itself as the case class accessor if it already has that name. But you still cannot write case class C(_2: Int, _1: String) nor should you be able to do this.
1 parent a5620ab commit 403a16f

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,9 @@ object desugar {
345345
DefDef(name, Nil, Nil, TypeTree(), rhs).withMods(synthetic)
346346
val isDefinedMeth = syntheticProperty(nme.isDefined, Literal(Constant(true)))
347347
val caseParams = constrVparamss.head.toArray
348-
val productElemMeths = for (i <- 0 until arity) yield
349-
syntheticProperty(nme.selectorName(i), Select(This(EmptyTypeIdent), caseParams(i).name))
348+
val productElemMeths =
349+
for (i <- 0 until arity if nme.selectorName(i) `ne` caseParams(i).name)
350+
yield syntheticProperty(nme.selectorName(i), Select(This(EmptyTypeIdent), caseParams(i).name))
350351
def isRepeated(tree: Tree): Boolean = tree match {
351352
case PostfixOp(_, nme.raw.STAR) => true
352353
case ByNameTypeTree(tree1) => isRepeated(tree1)

tests/pos/i1797.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
case class Tuple1[T](_1: T)

0 commit comments

Comments
 (0)