diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 77369c828113..f198caad0084 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -3425,14 +3425,16 @@ object Parsers { else mods.withPrivateWithin(ident().toTypeName) } if mods1.is(Local) then + val span = Span(startOffset, in.lastOffset) + val p = if mods1.is(Private) then "private" else "protected" report.errorOrMigrationWarning( em"""Ignoring [this] qualifier. - |This syntax will be deprecated in the future; it should be dropped. + |The syntax `$p[this]` will be deprecated in the future; just write `$p` instead. |See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html${rewriteNotice(`3.4-migration`)}""", - in.sourcePos(), + in.sourcePos().withSpan(span), MigrationVersion.RemoveThisQualifier) if MigrationVersion.RemoveThisQualifier.needsPatch then - patch(source, Span(startOffset, in.lastOffset), "") + patch(source, span, "") mods1 } else mods diff --git a/tests/semanticdb/metac.expect b/tests/semanticdb/metac.expect index a8ed97afe126..350464cec32d 100644 --- a/tests/semanticdb/metac.expect +++ b/tests/semanticdb/metac.expect @@ -43,12 +43,12 @@ Occurrences: [9:11..9:14): ??? -> scala/Predef.`???`(). Diagnostics: -[4:16..4:16): [warning] Ignoring [this] qualifier. -This syntax will be deprecated in the future; it should be dropped. +[4:9..4:15): [warning] Ignoring [this] qualifier. +The syntax `private[this]` will be deprecated in the future; just write `private` instead. See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html This construct can be rewritten automatically under -rewrite -source 3.4-migration. -[7:18..7:18): [warning] Ignoring [this] qualifier. -This syntax will be deprecated in the future; it should be dropped. +[7:11..7:17): [warning] Ignoring [this] qualifier. +The syntax `protected[this]` will be deprecated in the future; just write `protected` instead. See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html This construct can be rewritten automatically under -rewrite -source 3.4-migration. @@ -823,13 +823,13 @@ Occurrences: Diagnostics: [13:20..13:21): [warning] unused explicit parameter [18:9..18:10): [warning] unused explicit parameter -[20:23..20:23): [warning] Ignoring [this] qualifier. -This syntax will be deprecated in the future; it should be dropped. +[20:16..20:22): [warning] Ignoring [this] qualifier. +The syntax `private[this]` will be deprecated in the future; just write `private` instead. See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html This construct can be rewritten automatically under -rewrite -source 3.4-migration. [20:27..20:28): [warning] unused explicit parameter -[22:23..22:23): [warning] Ignoring [this] qualifier. -This syntax will be deprecated in the future; it should be dropped. +[22:16..22:22): [warning] Ignoring [this] qualifier. +The syntax `private[this]` will be deprecated in the future; just write `private` instead. See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html This construct can be rewritten automatically under -rewrite -source 3.4-migration. [22:27..22:28): [warning] unused explicit parameter @@ -4553,20 +4553,20 @@ Occurrences: Diagnostics: [2:20..2:21): [warning] unused explicit parameter -[5:16..5:16): [warning] Ignoring [this] qualifier. -This syntax will be deprecated in the future; it should be dropped. +[5:9..5:15): [warning] Ignoring [this] qualifier. +The syntax `private[this]` will be deprecated in the future; just write `private` instead. See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html This construct can be rewritten automatically under -rewrite -source 3.4-migration. -[7:16..7:16): [warning] Ignoring [this] qualifier. -This syntax will be deprecated in the future; it should be dropped. +[7:9..7:15): [warning] Ignoring [this] qualifier. +The syntax `private[this]` will be deprecated in the future; just write `private` instead. See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html This construct can be rewritten automatically under -rewrite -source 3.4-migration. -[12:16..12:16): [warning] Ignoring [this] qualifier. -This syntax will be deprecated in the future; it should be dropped. +[12:9..12:15): [warning] Ignoring [this] qualifier. +The syntax `private[this]` will be deprecated in the future; just write `private` instead. See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html This construct can be rewritten automatically under -rewrite -source 3.4-migration. -[13:16..13:16): [warning] Ignoring [this] qualifier. -This syntax will be deprecated in the future; it should be dropped. +[13:9..13:15): [warning] Ignoring [this] qualifier. +The syntax `private[this]` will be deprecated in the future; just write `private` instead. See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html This construct can be rewritten automatically under -rewrite -source 3.4-migration. diff --git a/tests/warn/private-this-3.4.check b/tests/warn/private-this-3.4.check index 2ba2fea549d1..f7d7adc084e6 100644 --- a/tests/warn/private-this-3.4.check +++ b/tests/warn/private-this-3.4.check @@ -1,14 +1,14 @@ --- Warning: tests/warn/private-this-3.4.scala:4:16 --------------------------------------------------------------------- +-- Warning: tests/warn/private-this-3.4.scala:4:9 ---------------------------------------------------------------------- 4 | private[this] def foo: Int = ??? // warn: migration warning - | ^ - | Ignoring [this] qualifier. - | This syntax will be deprecated in the future; it should be dropped. - | See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html - | This construct can be rewritten automatically under -rewrite -source 3.4-migration. --- Warning: tests/warn/private-this-3.4.scala:5:18 --------------------------------------------------------------------- + | ^^^^^^ + | Ignoring [this] qualifier. + | The syntax `private[this]` will be deprecated in the future; just write `private` instead. + | See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html + | This construct can be rewritten automatically under -rewrite -source 3.4-migration. +-- Warning: tests/warn/private-this-3.4.scala:5:11 --------------------------------------------------------------------- 5 | protected[this] def bar: Int = ??? // warn: migration warning - | ^ - | Ignoring [this] qualifier. - | This syntax will be deprecated in the future; it should be dropped. - | See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html - | This construct can be rewritten automatically under -rewrite -source 3.4-migration. + | ^^^^^^ + | Ignoring [this] qualifier. + | The syntax `protected[this]` will be deprecated in the future; just write `protected` instead. + | See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html + | This construct can be rewritten automatically under -rewrite -source 3.4-migration.