diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 3079b26df6cd..493a6e1cc18e 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -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) } diff --git a/tests/neg/i17981.check b/tests/neg/i17981.check new file mode 100644 index 000000000000..0ef7225d857e --- /dev/null +++ b/tests/neg/i17981.check @@ -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` diff --git a/tests/neg/i17981.scala b/tests/neg/i17981.scala new file mode 100644 index 000000000000..d2eaa0cfa7f2 --- /dev/null +++ b/tests/neg/i17981.scala @@ -0,0 +1 @@ +final final case class Foo() // error