Skip to content

Commit

Permalink
fix: report correct location on a repeat modifier (#17982)
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
ckipp01 authored and Kordyjan committed Nov 29, 2023
1 parent 3f693f7 commit 6fb812a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3028,7 +3028,9 @@ object Parsers {
val name = in.name
val mod = atSpan(in.skipToken()) { modOfToken(tok, name) }

if (mods.isOneOf(mod.flags)) syntaxError(RepeatedModifier(mod.flags.flagsString))
if mods.isOneOf(mod.flags) then
syntaxError(RepeatedModifier(mod.flags.flagsString), mod.span)

addMod(mods, mod)
}

Expand Down
6 changes: 6 additions & 0 deletions tests/neg/i17981.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- [E015] Syntax Error: tests/neg/i17981.scala:1:6 ---------------------------------------------------------------------
1 |final final case class Foo() // error
| ^^^^^
| Repeated modifier final
|
| longer explanation available when compiling with `-explain`
1 change: 1 addition & 0 deletions tests/neg/i17981.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
final final case class Foo() // error

0 comments on commit 6fb812a

Please sign in to comment.