From 6fb812a5bbdca0ee68697b07060d80c916c89774 Mon Sep 17 00:00:00 2001 From: Chris Kipp Date: Mon, 19 Jun 2023 15:32:48 +0200 Subject: [PATCH] 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 10180da5de14be45be59200f2a54c44e9ad94d46] --- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 4 +++- tests/neg/i17981.check | 6 ++++++ tests/neg/i17981.scala | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 tests/neg/i17981.check create mode 100644 tests/neg/i17981.scala 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