From 403a16f70edfc95da4b575bbee05d3d7cbc90704 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 15 Dec 2016 18:00:27 +0100 Subject: [PATCH] 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. --- compiler/src/dotty/tools/dotc/ast/Desugar.scala | 5 +++-- tests/pos/i1797.scala | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 tests/pos/i1797.scala diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 15cb0b665a5d..50463efb8853 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -345,8 +345,9 @@ object desugar { DefDef(name, Nil, Nil, TypeTree(), rhs).withMods(synthetic) val isDefinedMeth = syntheticProperty(nme.isDefined, Literal(Constant(true))) val caseParams = constrVparamss.head.toArray - val productElemMeths = for (i <- 0 until arity) yield - syntheticProperty(nme.selectorName(i), Select(This(EmptyTypeIdent), caseParams(i).name)) + val productElemMeths = + for (i <- 0 until arity if nme.selectorName(i) `ne` caseParams(i).name) + yield syntheticProperty(nme.selectorName(i), Select(This(EmptyTypeIdent), caseParams(i).name)) def isRepeated(tree: Tree): Boolean = tree match { case PostfixOp(_, nme.raw.STAR) => true case ByNameTypeTree(tree1) => isRepeated(tree1) diff --git a/tests/pos/i1797.scala b/tests/pos/i1797.scala new file mode 100644 index 000000000000..1f10082b78db --- /dev/null +++ b/tests/pos/i1797.scala @@ -0,0 +1 @@ +case class Tuple1[T](_1: T)