Skip to content

Commit 55faeeb

Browse files
committed
Improve this qualifier warning
1 parent 1c312cf commit 55faeeb

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3426,9 +3426,10 @@ object Parsers {
34263426
}
34273427
if mods1.is(Local) then
34283428
val span = Span(startOffset, in.lastOffset)
3429+
val p = if mods1.is(Private) then "private" else "protected"
34293430
report.errorOrMigrationWarning(
34303431
em"""Ignoring [this] qualifier.
3431-
|This syntax will be deprecated in the future; it should be dropped.
3432+
|The syntax `$p[this]` will be deprecated in the future; just write `$p` instead.
34323433
|See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html${rewriteNotice(`3.4-migration`)}""",
34333434
in.sourcePos().withSpan(span),
34343435
MigrationVersion.RemoveThisQualifier)

tests/semanticdb/metac.expect

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ Occurrences:
4343
[9:11..9:14): ??? -> scala/Predef.`???`().
4444

4545
Diagnostics:
46-
[4:16..4:16): [warning] Ignoring [this] qualifier.
47-
This syntax will be deprecated in the future; it should be dropped.
46+
[4:9..4:15): [warning] Ignoring [this] qualifier.
47+
The syntax `private[this]` will be deprecated in the future; just write `private` instead.
4848
See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html
4949
This construct can be rewritten automatically under -rewrite -source 3.4-migration.
50-
[7:18..7:18): [warning] Ignoring [this] qualifier.
51-
This syntax will be deprecated in the future; it should be dropped.
50+
[7:11..7:17): [warning] Ignoring [this] qualifier.
51+
The syntax `protected[this]` will be deprecated in the future; just write `protected` instead.
5252
See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html
5353
This construct can be rewritten automatically under -rewrite -source 3.4-migration.
5454

@@ -823,13 +823,13 @@ Occurrences:
823823
Diagnostics:
824824
[13:20..13:21): [warning] unused explicit parameter
825825
[18:9..18:10): [warning] unused explicit parameter
826-
[20:23..20:23): [warning] Ignoring [this] qualifier.
827-
This syntax will be deprecated in the future; it should be dropped.
826+
[20:16..20:22): [warning] Ignoring [this] qualifier.
827+
The syntax `private[this]` will be deprecated in the future; just write `private` instead.
828828
See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html
829829
This construct can be rewritten automatically under -rewrite -source 3.4-migration.
830830
[20:27..20:28): [warning] unused explicit parameter
831-
[22:23..22:23): [warning] Ignoring [this] qualifier.
832-
This syntax will be deprecated in the future; it should be dropped.
831+
[22:16..22:22): [warning] Ignoring [this] qualifier.
832+
The syntax `private[this]` will be deprecated in the future; just write `private` instead.
833833
See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html
834834
This construct can be rewritten automatically under -rewrite -source 3.4-migration.
835835
[22:27..22:28): [warning] unused explicit parameter
@@ -4553,20 +4553,20 @@ Occurrences:
45534553

45544554
Diagnostics:
45554555
[2:20..2:21): [warning] unused explicit parameter
4556-
[5:16..5:16): [warning] Ignoring [this] qualifier.
4557-
This syntax will be deprecated in the future; it should be dropped.
4556+
[5:9..5:15): [warning] Ignoring [this] qualifier.
4557+
The syntax `private[this]` will be deprecated in the future; just write `private` instead.
45584558
See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html
45594559
This construct can be rewritten automatically under -rewrite -source 3.4-migration.
4560-
[7:16..7:16): [warning] Ignoring [this] qualifier.
4561-
This syntax will be deprecated in the future; it should be dropped.
4560+
[7:9..7:15): [warning] Ignoring [this] qualifier.
4561+
The syntax `private[this]` will be deprecated in the future; just write `private` instead.
45624562
See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html
45634563
This construct can be rewritten automatically under -rewrite -source 3.4-migration.
4564-
[12:16..12:16): [warning] Ignoring [this] qualifier.
4565-
This syntax will be deprecated in the future; it should be dropped.
4564+
[12:9..12:15): [warning] Ignoring [this] qualifier.
4565+
The syntax `private[this]` will be deprecated in the future; just write `private` instead.
45664566
See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html
45674567
This construct can be rewritten automatically under -rewrite -source 3.4-migration.
4568-
[13:16..13:16): [warning] Ignoring [this] qualifier.
4569-
This syntax will be deprecated in the future; it should be dropped.
4568+
[13:9..13:15): [warning] Ignoring [this] qualifier.
4569+
The syntax `private[this]` will be deprecated in the future; just write `private` instead.
45704570
See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html
45714571
This construct can be rewritten automatically under -rewrite -source 3.4-migration.
45724572

tests/warn/private-this-3.4.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
4 | private[this] def foo: Int = ??? // warn: migration warning
33
| ^^^^^^
44
| Ignoring [this] qualifier.
5-
| This syntax will be deprecated in the future; it should be dropped.
5+
| The syntax `private[this]` will be deprecated in the future; just write `private` instead.
66
| See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html
77
| This construct can be rewritten automatically under -rewrite -source 3.4-migration.
88
-- Warning: tests/warn/private-this-3.4.scala:5:11 ---------------------------------------------------------------------
99
5 | protected[this] def bar: Int = ??? // warn: migration warning
1010
| ^^^^^^
1111
| Ignoring [this] qualifier.
12-
| This syntax will be deprecated in the future; it should be dropped.
12+
| The syntax `protected[this]` will be deprecated in the future; just write `protected` instead.
1313
| See: https://docs.scala-lang.org/scala3/reference/dropped-features/this-qualifier.html
1414
| This construct can be rewritten automatically under -rewrite -source 3.4-migration.

0 commit comments

Comments
 (0)