Skip to content

Commit 3c690d3

Browse files
committed
Add -Wall option
1 parent 62f0324 commit 3c690d3

File tree

3 files changed

+94
-6
lines changed

3 files changed

+94
-6
lines changed

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

+9-5
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,12 @@ private sealed trait WarningSettings:
163163
self: SettingGroup =>
164164

165165
val Whelp: Setting[Boolean] = BooleanSetting("-W", "Print a synopsis of warning options.")
166+
val Wall: Setting[Boolean] = BooleanSetting("-Wall", "Enable all warnings")
166167
val XfatalWarnings: Setting[Boolean] = BooleanSetting("-Werror", "Fail the compilation if there are any warnings.", aliases = List("-Xfatal-warnings"))
167-
val WvalueDiscard: Setting[Boolean] = BooleanSetting("-Wvalue-discard", "Warn when non-Unit expression results are unused.")
168-
val WNonUnitStatement = BooleanSetting("-Wnonunit-statement", "Warn when block statements are non-Unit expressions.")
169-
val WimplausiblePatterns = BooleanSetting("-Wimplausible-patterns", "Warn if comparison with a pattern value looks like it might always fail.")
170-
val WunstableInlineAccessors = BooleanSetting("-WunstableInlineAccessors", "Warn an inline methods has references to non-stable binary APIs.")
168+
val WvalueDiscard: Setting[Boolean] = BooleanSetting("-Wvalue-discard", "Warn when non-Unit expression results are unused.").overrideWith(Wall)
169+
val WNonUnitStatement = BooleanSetting("-Wnonunit-statement", "Warn when block statements are non-Unit expressions.").overrideWith(Wall)
170+
val WimplausiblePatterns = BooleanSetting("-Wimplausible-patterns", "Warn if comparison with a pattern value looks like it might always fail.").overrideWith(Wall)
171+
val WunstableInlineAccessors = BooleanSetting("-WunstableInlineAccessors", "Warn an inline methods has references to non-stable binary APIs.").overrideWith(Wall)
171172
val Wunused: Setting[List[ChoiceWithHelp[String]]] = MultiChoiceHelpSetting(
172173
name = "-Wunused",
173174
helpArg = "warning",
@@ -199,7 +200,10 @@ private sealed trait WarningSettings:
199200
)
200201
),
201202
default = Nil
202-
)
203+
).overrideWith(Wall, {
204+
case true => List(ChoiceWithHelp("all", ""))
205+
case false => Nil
206+
})
203207
object WunusedHas:
204208
def isChoiceSet(s: String)(using Context) = Wunused.value.pipe(us => us.contains(s))
205209
def allOr(s: String)(using Context) = Wunused.value.pipe(us => us.contains("all") || us.contains(s))

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

+18-1
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,27 @@ object Settings:
6464
depends: List[(Setting[?], Any)] = Nil,
6565
ignoreInvalidArgs: Boolean = false,
6666
propertyClass: Option[Class[?]] = None)(private[Settings] val idx: Int) {
67+
68+
private var overridenBy: Option[Setting[_]] = None
69+
private var overridenByMapper: Any => T = _
6770

6871
private var changed: Boolean = false
6972

70-
def valueIn(state: SettingsState): T = state.value(idx).asInstanceOf[T]
73+
def valueIn(state: SettingsState): T =
74+
overridenBy.map(_.valueIn(state)).map(overridenByMapper)
75+
.getOrElse(state.value(idx).asInstanceOf[T])
76+
77+
def overrideWith(setting: Setting[T]): Setting[T] = {
78+
overridenBy = Some(setting)
79+
overridenByMapper = _.asInstanceOf[T]
80+
this
81+
}
82+
83+
def overrideWith[A](setting: Setting[A], mapper: A => T): Setting[T] = {
84+
overridenBy = Some(setting)
85+
overridenByMapper = mapper.asInstanceOf[Any => T]
86+
this
87+
}
7188

7289
def updateIn(state: SettingsState, x: Any): SettingsState = x match
7390
case _: T => state.update(idx, x)

tests/neg/i18559.scala

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
//> using options -Werror -Wall
2+
3+
val b = // OK
4+
var e3 = 2 // error
5+
1
6+
7+
object FooUnused:
8+
import collection.mutable.Set // error
9+
import collection.mutable.{Map => MutMap} // error
10+
import collection.mutable._ // error
11+
12+
object FooWildcardUnused:
13+
import collection.mutable._ // error
14+
15+
object Foo:
16+
import collection.mutable.Set // OK
17+
import collection.mutable.{Map => MutMap} // OK
18+
19+
val bar = Set() // OK
20+
val baz = MutMap() // OK
21+
22+
sealed trait Calc
23+
sealed trait Const extends Calc
24+
case class Sum(a: Calc, b: Calc) extends Calc
25+
case class S(pred: Const) extends Const
26+
case object Z extends Const
27+
28+
val a = Sum(S(S(Z)),Z) match {
29+
case Sum(a,Z) => Z // error
30+
// case Sum(a @ _,Z) => Z // todo : this should pass in the future
31+
case Sum(a@S(_),Z) => Z // error
32+
case Sum(a@S(_),Z) => a // OK
33+
case Sum(a@S(b@S(_)), Z) => a // error
34+
case Sum(a@S(b@S(_)), Z) => a // error
35+
case Sum(a@S(b@(S(_))), Z) => Sum(a,b) // OK
36+
case Sum(_,_) => Z // OK
37+
case _ => Z // OK
38+
}
39+
40+
import scala.util.{Either, Right, Left}
41+
import scala.collection.mutable
42+
43+
case class Failed(msg: String)
44+
45+
def firstThing(): Either[Failed, Unit] =
46+
Right(())
47+
48+
def secondThing(): Either[Failed, Unit] =
49+
Left(Failed("whoops you should have flatMapped me"))
50+
51+
def singleExpr(): Either[Failed, Unit] =
52+
firstThing().map(_ => secondThing()) // error
53+
54+
def block(): Either[Failed, Unit] = {
55+
firstThing().map(_ => secondThing()) // error
56+
}
57+
58+
class C {
59+
import concurrent._
60+
import ExecutionContext.Implicits._
61+
def c = {
62+
def improved = Future(42)
63+
def stale = Future(27)
64+
improved // error
65+
stale
66+
}
67+
}

0 commit comments

Comments
 (0)