Skip to content

Commit 08f807c

Browse files
committed
Make -Wunused:patvars to unsafe
- Suppress -Wunused:patvars - Replace by -Wunused:unsafe-warn-patvars
1 parent 1db9040 commit 08f807c

File tree

3 files changed

+39
-18
lines changed

3 files changed

+39
-18
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,24 @@ private sealed trait WarningSettings:
171171
name = "imports",
172172
description = "Warn if an import selector is not referenced.\n" +
173173
"NOTE : overrided by -Wunused:strict-no-implicit-warn"),
174-
ChoiceWithHelp("patvars","Warn if a variable bound in a pattern is unused"),
175-
ChoiceWithHelp("privates","Warn if a private member is unused"),
176-
ChoiceWithHelp("locals","Warn if a local definition is unused"),
177-
ChoiceWithHelp("explicits","Warn if an explicit parameter is unused"),
178-
ChoiceWithHelp("implicits","Warn if an implicit parameter is unused"),
179-
ChoiceWithHelp("params","Enable -Wunused:explicits,implicits"),
180-
ChoiceWithHelp("linted","Enable -Wunused:imports,privates,locals,implicits"),
181-
ChoiceWithHelp(
182-
name = "strict-no-implicit-warn",
183-
description = "Same as -Wunused:import, only for imports of explicit named members.\n" +
184-
"NOTE : This overrides -Wunused:imports and NOT set by -Wunused:all"
185-
)
174+
ChoiceWithHelp("privates","Warn if a private member is unused"),
175+
ChoiceWithHelp("locals","Warn if a local definition is unused"),
176+
ChoiceWithHelp("explicits","Warn if an explicit parameter is unused"),
177+
ChoiceWithHelp("implicits","Warn if an implicit parameter is unused"),
178+
ChoiceWithHelp("params","Enable -Wunused:explicits,implicits"),
179+
ChoiceWithHelp("linted","Enable -Wunused:imports,privates,locals,implicits"),
180+
ChoiceWithHelp(
181+
name = "strict-no-implicit-warn",
182+
description = "Same as -Wunused:import, only for imports of explicit named members.\n" +
183+
"NOTE : This overrides -Wunused:imports and NOT set by -Wunused:all"
184+
),
185+
// ChoiceWithHelp("patvars","Warn if a variable bound in a pattern is unused"),
186+
ChoiceWithHelp(
187+
name = "unsafe-warn-patvars",
188+
description = "(UNSAFE) Warn if a variable bound in a pattern is unused.\n" +
189+
"This warning can generate false positive, as warning cannot be\n" +
190+
"suppressed yet."
191+
)
186192
),
187193
default = Nil
188194
)
@@ -206,7 +212,8 @@ private sealed trait WarningSettings:
206212
def privates(using Context) =
207213
allOr("privates") || allOr("linted")
208214
def patvars(using Context) =
209-
allOr("patvars")
215+
isChoiceSet("unsafe-warn-patvars") // not with "all"
216+
// allOr("patvars") // todo : rename once fixed
210217
def linted(using Context) =
211218
allOr("linted")
212219
def strictNoImplicitWarn(using Context) =

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// scalac: -Wunused:patvars
1+
// scalac: -Wunused:unsafe-warn-patvars
2+
// todo : change to :patvars
23

34
sealed trait Calc
45
sealed trait Const extends Calc
@@ -8,10 +9,22 @@ case object Z extends Const
89

910
val a = Sum(S(S(Z)),Z) match {
1011
case Sum(a,Z) => Z // error
12+
// case Sum(a @ _,Z) => Z // todo : this should pass in the future
1113
case Sum(a@S(_),Z) => Z // error
1214
case Sum(a@S(_),Z) => a // OK
1315
case Sum(a@S(b@S(_)), Z) => a // error
16+
case Sum(a@S(b@S(_)), Z) => a // error
1417
case Sum(a@S(b@(S(_))), Z) => Sum(a,b) // OK
1518
case Sum(_,_) => Z // OK
1619
case _ => Z // OK
1720
}
21+
22+
// todo : This should pass in the future
23+
// val b = for {
24+
// case Some(x) <- Option(Option(1))
25+
// } println(s"$x")
26+
27+
// todo : This should *NOT* pass in the future
28+
// val c = for {
29+
// case Some(x) <- Option(Option(1))
30+
// } println(s"hello world")

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ class A {
2929
def g = 4 // OK
3030
y + g
3131

32-
def g(x: Int): Int = x match
33-
case x:1 => 0 // error
34-
case x:2 => x // OK
35-
case _ => 1 // OK
32+
// todo : uncomment once patvars is fixed
33+
// def g(x: Int): Int = x match
34+
// case x:1 => 0 // ?error
35+
// case x:2 => x // ?OK
36+
// case _ => 1 // ?OK
3637
}
3738

3839
/* ---- CHECK scala.annotation.unused ---- */

0 commit comments

Comments
 (0)