Skip to content

Commit 6fb812a

Browse files
ckipp01Kordyjan
authored andcommitted
fix: report correct location on a repeat modifier (#17982)
Currently given the following code snippet: ```scala final final case class Foo() ``` The error is reported on `Foo` and not on the repeated modifier. This changes the reporting to instead report on the repeated modifier `final`. Fixes #17981 [Cherry-picked 10180da]
1 parent 3f693f7 commit 6fb812a

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3028,7 +3028,9 @@ object Parsers {
30283028
val name = in.name
30293029
val mod = atSpan(in.skipToken()) { modOfToken(tok, name) }
30303030

3031-
if (mods.isOneOf(mod.flags)) syntaxError(RepeatedModifier(mod.flags.flagsString))
3031+
if mods.isOneOf(mod.flags) then
3032+
syntaxError(RepeatedModifier(mod.flags.flagsString), mod.span)
3033+
30323034
addMod(mods, mod)
30333035
}
30343036

tests/neg/i17981.check

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- [E015] Syntax Error: tests/neg/i17981.scala:1:6 ---------------------------------------------------------------------
2+
1 |final final case class Foo() // error
3+
| ^^^^^
4+
| Repeated modifier final
5+
|
6+
| longer explanation available when compiling with `-explain`

tests/neg/i17981.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
final final case class Foo() // error

0 commit comments

Comments
 (0)