Skip to content

Commit a1cde6d

Browse files
committed
more review feedback
1 parent 7aa41ca commit a1cde6d

File tree

5 files changed

+74
-58
lines changed

5 files changed

+74
-58
lines changed

compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,7 @@ enum ErrorMessageID extends java.lang.Enum[ErrorMessageID]:
179179
def errorNumber = ordinal - 2
180180

181181
object ErrorMessageID:
182-
def fromErrorNumber(n: Int) = fromOrdinal(n + 2)
182+
def fromErrorNumber(n: Int): Option[ErrorMessageID] =
183+
val enumId = n + 2
184+
if enumId >= 2 && enumId < ErrorMessageID.values.length then Some(fromOrdinal(enumId))
185+
else None

compiler/src/dotty/tools/dotc/reporting/WConf.scala

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ object WConf:
5757

5858
def parseFilters(s: String): Either[List[String], List[MessageFilter]] =
5959
// TODO: don't split on escaped \&
60-
val (parseErrors, filters) = s.split('&').view.map(parseFilter).toList.partitionMap(identity)
60+
val (parseErrors, filters) = s.split('&').toList.partitionMap(parseFilter)
6161
if parseErrors.nonEmpty then Left(parseErrors)
6262
else if filters.isEmpty then Left(List("no filters or no action defined"))
6363
else Right(filters)
@@ -68,11 +68,9 @@ object WConf:
6868
case "msg" => regex(conf).map(MessagePattern.apply)
6969
case "id" => conf match
7070
case ErrorId(num) =>
71-
val n = num.toInt
72-
if n < ErrorMessageID.values.length then
73-
Right(MessageID(ErrorMessageID.fromErrorNumber(n)))
74-
else
75-
Left(s"unknonw error message id: E$n")
71+
ErrorMessageID.fromErrorNumber(num.toInt) match
72+
case Some(errId) => Right(MessageID(errId))
73+
case _ => Left(s"unknonw error message number: E$num")
7674
case _ =>
7775
Left(s"invalid error message id: $conf")
7876
case "name" =>
@@ -119,7 +117,7 @@ object WConf:
119117
class Suppression(val annotPos: SourcePosition, filters: List[MessageFilter], val start: Int, end: Int, val verbose: Boolean):
120118
private[this] var _used = false
121119
def used: Boolean = _used
122-
def markUsed(): Unit = _used = true
120+
def markUsed(): Unit = { _used = true }
123121

124122
def matches(dia: Diagnostic): Boolean =
125123
val pos = dia.pos

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

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2090,27 +2090,24 @@ class Typer extends Namer
20902090
val annot = Annotations.Annotation(tree)
20912091
def argPos = annot.argument(0).getOrElse(tree).sourcePos
20922092
var verbose = false
2093-
var erroneous = false
2094-
val filters =
2095-
if annot.arguments.isEmpty then List(MessageFilter.Any)
2096-
else annot.argumentConstantString(0) match
2097-
case None => annot.argument(0) match
2098-
case Some(t: Select) if t.name.is(DefaultGetterName) =>
2099-
// default argument used for `@nowarn` and `@nowarn()`
2100-
List(MessageFilter.Any)
2101-
case _ =>
2102-
report.warning(s"filter needs to be a compile-time constant string", argPos)
2103-
List(MessageFilter.None)
2104-
case Some("") =>
2105-
List(MessageFilter.Any)
2106-
case Some("verbose") | Some("v") =>
2107-
verbose = true
2093+
val filters = annot.argumentConstantString(0) match
2094+
case None => annot.argument(0) match
2095+
case Some(t: Select) if t.name.is(DefaultGetterName) =>
2096+
// default argument used for `@nowarn` and `@nowarn()`
21082097
List(MessageFilter.Any)
2109-
case Some(s) =>
2110-
WConf.parseFilters(s).fold(parseErrors =>
2111-
report.warning (s"Invalid message filter\n${parseErrors.mkString ("\n")}", argPos)
2112-
List(MessageFilter.None),
2113-
identity)
2098+
case _ =>
2099+
report.warning(s"filter needs to be a compile-time constant string", argPos)
2100+
List(MessageFilter.None)
2101+
case Some("") =>
2102+
List(MessageFilter.Any)
2103+
case Some("verbose") | Some("v") =>
2104+
verbose = true
2105+
List(MessageFilter.Any)
2106+
case Some(s) =>
2107+
WConf.parseFilters(s).left.map(parseErrors =>
2108+
report.warning (s"Invalid message filter\n${parseErrors.mkString ("\n")}", argPos)
2109+
List(MessageFilter.None)
2110+
).merge
21142111
val range = mdef.sourcePos
21152112
val sup = Suppression(tree.sourcePos, filters, range.start, range.end, verbose)
21162113
// invalid suppressions, don't report as unused

tests/neg-custom-args/nowarn/nowarn.check

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@
55
| its body in a block; no exceptions are handled.
66

77
longer explanation available when compiling with `-explain`
8-
-- [E000] Syntax Warning: tests/neg-custom-args/nowarn/nowarn.scala:24:26 ----------------------------------------------
9-
24 |@nowarn("id=1") def t4d = try 1 // error and warning (unused nowarn, wrong id)
8+
-- [E000] Syntax Warning: tests/neg-custom-args/nowarn/nowarn.scala:23:25 ----------------------------------------------
9+
23 |@nowarn(o.inl) def t2d = try 1 // two warnings (`inl` is not a compile-time constant)
10+
| ^^^^^
11+
| A try without catch or finally is equivalent to putting
12+
| its body in a block; no exceptions are handled.
13+
14+
longer explanation available when compiling with `-explain`
15+
-- [E000] Syntax Warning: tests/neg-custom-args/nowarn/nowarn.scala:31:26 ----------------------------------------------
16+
31 |@nowarn("id=1") def t4d = try 1 // error and warning (unused nowarn, wrong id)
1017
| ^^^^^
1118
| A try without catch or finally is equivalent to putting
1219
| its body in a block; no exceptions are handled.
1320

1421
longer explanation available when compiling with `-explain`
15-
-- [E000] Syntax Warning: tests/neg-custom-args/nowarn/nowarn.scala:26:28 ----------------------------------------------
16-
26 |@nowarn("verbose") def t5 = try 1 // warning with details
22+
-- [E000] Syntax Warning: tests/neg-custom-args/nowarn/nowarn.scala:33:28 ----------------------------------------------
23+
33 |@nowarn("verbose") def t5 = try 1 // warning with details
1724
| ^^^^^
1825
| A try without catch or finally is equivalent to putting
1926
| its body in a block; no exceptions are handled.
@@ -43,55 +50,59 @@ longer explanation available when compiling with `-explain`
4350
15 |@nowarn(t1a.toString) // warning (typer, argument not a compile-time constant)
4451
| ^^^^^^^^^^^^
4552
| filter needs to be a compile-time constant string
46-
-- Deprecation Warning: tests/neg-custom-args/nowarn/nowarn.scala:30:10 ------------------------------------------------
47-
30 |def t6a = f // warning (refchecks, deprecation)
53+
-- Warning: tests/neg-custom-args/nowarn/nowarn.scala:23:10 ------------------------------------------------------------
54+
23 |@nowarn(o.inl) def t2d = try 1 // two warnings (`inl` is not a compile-time constant)
55+
| ^^^^^
56+
| filter needs to be a compile-time constant string
57+
-- Deprecation Warning: tests/neg-custom-args/nowarn/nowarn.scala:37:10 ------------------------------------------------
58+
37 |def t6a = f // warning (refchecks, deprecation)
4859
| ^
4960
| method f is deprecated
50-
-- Deprecation Warning: tests/neg-custom-args/nowarn/nowarn.scala:33:30 ------------------------------------------------
51-
33 |@nowarn("msg=fish") def t6d = f // error (unused nowarn), warning (deprecation)
61+
-- Deprecation Warning: tests/neg-custom-args/nowarn/nowarn.scala:40:30 ------------------------------------------------
62+
40 |@nowarn("msg=fish") def t6d = f // error (unused nowarn), warning (deprecation)
5263
| ^
5364
| method f is deprecated
54-
-- Deprecation Warning: tests/neg-custom-args/nowarn/nowarn.scala:40:10 ------------------------------------------------
55-
40 |def t7c = f: // warning (deprecation)
65+
-- Deprecation Warning: tests/neg-custom-args/nowarn/nowarn.scala:47:10 ------------------------------------------------
66+
47 |def t7c = f: // warning (deprecation)
5667
| ^
5768
| method f is deprecated
58-
-- Unchecked Warning: tests/neg-custom-args/nowarn/nowarn.scala:46:7 ---------------------------------------------------
59-
46 | case _: List[Int] => 0 // warning (patmat, unchecked)
69+
-- Unchecked Warning: tests/neg-custom-args/nowarn/nowarn.scala:53:7 ---------------------------------------------------
70+
53 | case _: List[Int] => 0 // warning (patmat, unchecked)
6071
| ^
6172
| the type test for List[Int] cannot be checked at runtime
62-
-- Error: tests/neg-custom-args/nowarn/nowarn.scala:24:1 ---------------------------------------------------------------
63-
24 |@nowarn("id=1") def t4d = try 1 // error and warning (unused nowarn, wrong id)
73+
-- Error: tests/neg-custom-args/nowarn/nowarn.scala:31:1 ---------------------------------------------------------------
74+
31 |@nowarn("id=1") def t4d = try 1 // error and warning (unused nowarn, wrong id)
6475
|^^^^^^^^^^^^^^^
6576
|@nowarn annotation does not suppress any warnings
66-
-- Error: tests/neg-custom-args/nowarn/nowarn.scala:33:1 ---------------------------------------------------------------
67-
33 |@nowarn("msg=fish") def t6d = f // error (unused nowarn), warning (deprecation)
77+
-- Error: tests/neg-custom-args/nowarn/nowarn.scala:40:1 ---------------------------------------------------------------
78+
40 |@nowarn("msg=fish") def t6d = f // error (unused nowarn), warning (deprecation)
6879
|^^^^^^^^^^^^^^^^^^^
6980
|@nowarn annotation does not suppress any warnings
70-
-- Error: tests/neg-custom-args/nowarn/nowarn.scala:41:3 ---------------------------------------------------------------
71-
41 | @nowarn("msg=fish") // error (unused nowarn)
81+
-- Error: tests/neg-custom-args/nowarn/nowarn.scala:48:3 ---------------------------------------------------------------
82+
48 | @nowarn("msg=fish") // error (unused nowarn)
7283
| ^^^^^^^^^^^^^^^^^^^
7384
| @nowarn annotation does not suppress any warnings
74-
-- Error: tests/neg-custom-args/nowarn/nowarn.scala:53:0 ---------------------------------------------------------------
75-
53 |@nowarn def t9a = { 1: @nowarn; 2 } // error (outer @nowarn is unused)
85+
-- Error: tests/neg-custom-args/nowarn/nowarn.scala:60:0 ---------------------------------------------------------------
86+
60 |@nowarn def t9a = { 1: @nowarn; 2 } // error (outer @nowarn is unused)
7687
|^^^^^^^
7788
|@nowarn annotation does not suppress any warnings
78-
-- Error: tests/neg-custom-args/nowarn/nowarn.scala:54:27 --------------------------------------------------------------
79-
54 |@nowarn def t9b = { 1: Int @nowarn; 2 } // error (inner @nowarn is unused, it covers the type, not the expression)
89+
-- Error: tests/neg-custom-args/nowarn/nowarn.scala:61:27 --------------------------------------------------------------
90+
61 |@nowarn def t9b = { 1: Int @nowarn; 2 } // error (inner @nowarn is unused, it covers the type, not the expression)
8091
| ^^^^^^^
8192
| @nowarn annotation does not suppress any warnings
82-
-- Error: tests/neg-custom-args/nowarn/nowarn.scala:59:0 ---------------------------------------------------------------
83-
59 |@nowarn @ann(f) def t10b = 0 // error (unused nowarn)
93+
-- Error: tests/neg-custom-args/nowarn/nowarn.scala:66:0 ---------------------------------------------------------------
94+
66 |@nowarn @ann(f) def t10b = 0 // error (unused nowarn)
8495
|^^^^^^^
8596
|@nowarn annotation does not suppress any warnings
86-
-- Error: tests/neg-custom-args/nowarn/nowarn.scala:60:8 ---------------------------------------------------------------
87-
60 |@ann(f: @nowarn) def t10c = 0 // error (unused nowarn), should be silent
97+
-- Error: tests/neg-custom-args/nowarn/nowarn.scala:67:8 ---------------------------------------------------------------
98+
67 |@ann(f: @nowarn) def t10c = 0 // error (unused nowarn), should be silent
8899
| ^^^^^^^
89100
| @nowarn annotation does not suppress any warnings
90-
-- Error: tests/neg-custom-args/nowarn/nowarn.scala:63:0 ---------------------------------------------------------------
91-
63 |@nowarn class I1a { // error (unused nowarn)
101+
-- Error: tests/neg-custom-args/nowarn/nowarn.scala:70:0 ---------------------------------------------------------------
102+
70 |@nowarn class I1a { // error (unused nowarn)
92103
|^^^^^^^
93104
|@nowarn annotation does not suppress any warnings
94-
-- Error: tests/neg-custom-args/nowarn/nowarn.scala:68:0 ---------------------------------------------------------------
95-
68 |@nowarn class I1b { // error (unused nowarn)
105+
-- Error: tests/neg-custom-args/nowarn/nowarn.scala:75:0 ---------------------------------------------------------------
106+
75 |@nowarn class I1b { // error (unused nowarn)
96107
|^^^^^^^
97108
|@nowarn annotation does not suppress any warnings

tests/neg-custom-args/nowarn/nowarn.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ def t2 = { 1; 2 } // warning (the invalid nowarn doesn't silence anything)
1515
@nowarn(t1a.toString) // warning (typer, argument not a compile-time constant)
1616
def t2a = { 1; 2 } // warning (invalid nowarn doesn't silence)
1717

18+
object o:
19+
final val const = "msg=try"
20+
inline def inl = "msg=try"
21+
22+
@nowarn(o.const) def t2c = try 1 // no warning
23+
@nowarn(o.inl) def t2d = try 1 // two warnings (`inl` is not a compile-time constant)
24+
1825
@nowarn("id=E129") def t3a = { 1; 2 }
1926
@nowarn("name=PureExpressionInStatementPosition") def t3b = { 1; 2 }
2027

0 commit comments

Comments
 (0)