Skip to content

Commit 9e20f8b

Browse files
author
Niklas Vest
committed
Support multiple warnings per annotation
1 parent 12a25f2 commit 9e20f8b

File tree

3 files changed

+25
-28
lines changed

3 files changed

+25
-28
lines changed

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -940,12 +940,14 @@ object RefChecks {
940940
do
941941
// matches quoted references such as "${(A)}", "${(Abc)}", etc.
942942
val reference = """(?<=\$\{)[a-zA-Z]+(?=\})""".r
943-
val matches = reference.findAllMatchIn(arg)
944-
for Match(ref) <- matches if !sd.typeParams.exists(_.denot.name.show == ref) do
945-
val msg = InvalidReferenceInImplicitNotFoundAnnotation(ref, sd.name.show)
946-
val pos = ctx.source.atSpan(l.span)
943+
val matches = reference.findAllIn(arg)
944+
for m <- matches if !sd.typeParams.exists(_.denot.name.show == m) do
945+
val msg = InvalidReferenceInImplicitNotFoundAnnotation(m, sd.name.show)
946+
val span = l.span.shift(matches.start + 1) // +1 because of 0-based index
947+
val pos = ctx.source.atSpan(span.withEnd(span.start))
947948
report.warning(msg, pos)
948949

950+
949951
}
950952
import RefChecks._
951953

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
1-
-- [E157] Reference Error: tests/neg-custom-args/fatal-warnings/i4008.scala:5:29 ---------------------------------------
1+
-- [E157] Reference Error: tests/neg-custom-args/fatal-warnings/i4008.scala:5:56 ---------------------------------------
22
5 |@annotation.implicitNotFound("An implicit ShouldWarn1[${B}] is not in scope") // error
3-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4-
| Invalid reference to a type variable "B" found in the annotation argument.
5-
| The variable does not occur in the signature of ShouldWarn1.
6-
-- [E157] Reference Error: tests/neg-custom-args/fatal-warnings/i4008.scala:9:29 ---------------------------------------
3+
| ^
4+
| Invalid reference to a type variable "B" found in the annotation argument.
5+
| The variable does not occur in the signature of ShouldWarn1.
6+
-- [E157] Reference Error: tests/neg-custom-args/fatal-warnings/i4008.scala:9:56 ---------------------------------------
77
9 |@annotation.implicitNotFound("An implicit ShouldWarn2[${A}] is not in scope") // error
8-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9-
| Invalid reference to a type variable "A" found in the annotation argument.
10-
| The variable does not occur in the signature of ShouldWarn2.
11-
-- [E157] Reference Error: tests/neg-custom-args/fatal-warnings/i4008.scala:13:29 --------------------------------------
8+
| ^
9+
| Invalid reference to a type variable "A" found in the annotation argument.
10+
| The variable does not occur in the signature of ShouldWarn2.
11+
-- [E157] Reference Error: tests/neg-custom-args/fatal-warnings/i4008.scala:13:56 --------------------------------------
1212
13 |@annotation.implicitNotFound("An implicit ShouldWarn3[${A},${B}] is not in scope") // error
13-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14-
| Invalid reference to a type variable "A" found in the annotation argument.
15-
| The variable does not occur in the signature of ShouldWarn3.
16-
-- [E157] Reference Error: tests/neg-custom-args/fatal-warnings/i4008.scala:17:29 --------------------------------------
17-
17 |@annotation.implicitNotFound("An implicit ShouldWarn4[${A},${B}] is not in scope") // error
18-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
19-
| Invalid reference to a type variable "A" found in the annotation argument.
20-
| The variable does not occur in the signature of ShouldWarn4.
21-
-- [E157] Reference Error: tests/neg-custom-args/fatal-warnings/i4008.scala:21:29 --------------------------------------
13+
| ^
14+
| Invalid reference to a type variable "A" found in the annotation argument.
15+
| The variable does not occur in the signature of ShouldWarn3.
16+
-- [E157] Reference Error: tests/neg-custom-args/fatal-warnings/i4008.scala:21:61 --------------------------------------
2217
21 |@annotation.implicitNotFound("An implicit ShouldWarn5[${C},${Abc}] is not in scope") // error
23-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24-
| Invalid reference to a type variable "Abc" found in the annotation argument.
25-
| The variable does not occur in the signature of ShouldWarn5.
18+
| ^
19+
| Invalid reference to a type variable "Abc" found in the annotation argument.
20+
| The variable does not occur in the signature of ShouldWarn5.

tests/neg-custom-args/fatal-warnings/i4008.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ trait ShouldWarn2[B]
1414
trait ShouldWarn3[B, C]
1515

1616
// class, 2TP, 2 invalid refs
17-
@annotation.implicitNotFound("An implicit ShouldWarn4[${A},${B}] is not in scope") // error
18-
class ShouldWarn4[C, D]
17+
// @annotation.implicitNotFound("An implicit ShouldWarn4[${A},${B}] is not in scope")
18+
// class ShouldWarn4[C, D]
1919

2020
// class, 2TP, 1 invalid multi-char refs
2121
@annotation.implicitNotFound("An implicit ShouldWarn5[${C},${Abc}] is not in scope") // error
@@ -45,7 +45,7 @@ class ShouldntWarn4[Hello, World]
4545
class C[A]
4646

4747
object x {
48-
def someMethod[A](using @annotation.implicitNotFound("No C[${A}] found") sc: C[A]) = ???
48+
def someMethod[A](using @annotation.implicitNotFound("No C[${B}] found") sc: C[A]) = ???
4949
}
5050

5151

0 commit comments

Comments
 (0)