Skip to content

Commit 3122b3b

Browse files
committed
Error mentions bad _1 selector
1 parent 4458ab6 commit 3122b3b

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

compiler/src/dotty/tools/dotc/reporting/messages.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2457,6 +2457,12 @@ extends NamingMsg(DoubleDefinitionID):
24572457
i"have the same$nameAnd type $erasedType after erasure.$hint"
24582458
}
24592459
}
2460+
else if decl.is(CaseAccessor) || previousDecl.is(CaseAccessor) then
2461+
val selector = """_(\d+)""".r
2462+
decl.name.toString match
2463+
case selector(n) =>
2464+
s"${decl.name} is a case element selector and must name the ${n}th element"
2465+
case _ => ""
24602466
else ""
24612467
def symLocation(sym: Symbol) = {
24622468
val lineDesc =

tests/neg/i4520.check

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- [E120] Naming Error: tests/neg/i4520.scala:6:46 ---------------------------------------------------------------------
2+
6 |case class LabeledEdge[T, U](_1: T, label: U, _2: T) extends EdgeLike[T] // error
3+
| ^
4+
| Conflicting definitions:
5+
| def _2: U in class LabeledEdge at line 6 and
6+
| val _2: T in class LabeledEdge at line 6
7+
| _2 is a case element selector and must name the 2th element
8+
|
9+
| longer explanation available when compiling with `-explain`

tests/neg/i4520.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
trait EdgeLike[T] {
2+
def _1: T
3+
def _2: T
4+
}
5+
6+
case class LabeledEdge[T, U](_1: T, label: U, _2: T) extends EdgeLike[T] // error

0 commit comments

Comments
 (0)