Skip to content

Commit 5727187

Browse files
committed
Add -Wall
1 parent dea3d10 commit 5727187

File tree

8 files changed

+50
-36
lines changed

8 files changed

+50
-36
lines changed

Diff for: compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

+41-27
Original file line numberDiff line numberDiff line change
@@ -158,49 +158,53 @@ private sealed trait WarningSettings:
158158

159159
val Whelp: Setting[Boolean] = BooleanSetting(WarningSetting, "W", "Print a synopsis of warning options.")
160160
val XfatalWarnings: Setting[Boolean] = BooleanSetting(WarningSetting, "Werror", "Fail the compilation if there are any warnings.", aliases = List("-Xfatal-warnings"))
161-
val WvalueDiscard: Setting[Boolean] = BooleanSetting(WarningSetting, "Wvalue-discard", "Warn when non-Unit expression results are unused.")
162-
val WNonUnitStatement = BooleanSetting(WarningSetting, "Wnonunit-statement", "Warn when block statements are non-Unit expressions.")
163-
val WenumCommentDiscard = BooleanSetting(WarningSetting, "Wenum-comment-discard", "Warn when a comment ambiguously assigned to multiple enum cases is discarded.")
164-
val WimplausiblePatterns = BooleanSetting(WarningSetting, "Wimplausible-patterns", "Warn if comparison with a pattern value looks like it might always fail.")
165-
val WunstableInlineAccessors = BooleanSetting(WarningSetting, "WunstableInlineAccessors", "Warn an inline methods has references to non-stable binary APIs.")
166-
val Wunused: Setting[List[ChoiceWithHelp[String]]] = MultiChoiceHelpSetting(
161+
val Wall: Setting[Boolean] = BooleanSetting(WarningSetting, "Wall", "Enable all warning settings.")
162+
private val WvalueDiscard: Setting[Boolean] = BooleanSetting(WarningSetting, "Wvalue-discard", "Warn when non-Unit expression results are unused.")
163+
private val WNonUnitStatement = BooleanSetting(WarningSetting, "Wnonunit-statement", "Warn when block statements are non-Unit expressions.")
164+
private val WenumCommentDiscard = BooleanSetting(WarningSetting, "Wenum-comment-discard", "Warn when a comment ambiguously assigned to multiple enum cases is discarded.")
165+
private val WimplausiblePatterns = BooleanSetting(WarningSetting, "Wimplausible-patterns", "Warn if comparison with a pattern value looks like it might always fail.")
166+
private val WunstableInlineAccessors = BooleanSetting(WarningSetting, "WunstableInlineAccessors", "Warn an inline methods has references to non-stable binary APIs.")
167+
private val Wunused: Setting[List[ChoiceWithHelp[String]]] = MultiChoiceHelpSetting(
167168
WarningSetting,
168169
name = "Wunused",
169170
helpArg = "warning",
170171
descr = "Enable or disable specific `unused` warnings",
171172
choices = List(
172173
ChoiceWithHelp("nowarn", ""),
173-
ChoiceWithHelp("all",""),
174+
ChoiceWithHelp("all", ""),
174175
ChoiceWithHelp(
175176
name = "imports",
176177
description = "Warn if an import selector is not referenced.\n" +
177178
"NOTE : overrided by -Wunused:strict-no-implicit-warn"),
178-
ChoiceWithHelp("privates","Warn if a private member is unused"),
179-
ChoiceWithHelp("locals","Warn if a local definition is unused"),
180-
ChoiceWithHelp("explicits","Warn if an explicit parameter is unused"),
181-
ChoiceWithHelp("implicits","Warn if an implicit parameter is unused"),
182-
ChoiceWithHelp("params","Enable -Wunused:explicits,implicits"),
183-
ChoiceWithHelp("linted","Enable -Wunused:imports,privates,locals,implicits"),
184-
ChoiceWithHelp(
185-
name = "strict-no-implicit-warn",
186-
description = "Same as -Wunused:import, only for imports of explicit named members.\n" +
187-
"NOTE : This overrides -Wunused:imports and NOT set by -Wunused:all"
188-
),
189-
// ChoiceWithHelp("patvars","Warn if a variable bound in a pattern is unused"),
190-
ChoiceWithHelp(
191-
name = "unsafe-warn-patvars",
192-
description = "(UNSAFE) Warn if a variable bound in a pattern is unused.\n" +
193-
"This warning can generate false positive, as warning cannot be\n" +
194-
"suppressed yet."
195-
)
179+
ChoiceWithHelp("privates", "Warn if a private member is unused"),
180+
ChoiceWithHelp("locals", "Warn if a local definition is unused"),
181+
ChoiceWithHelp("explicits", "Warn if an explicit parameter is unused"),
182+
ChoiceWithHelp("implicits", "Warn if an implicit parameter is unused"),
183+
ChoiceWithHelp("params", "Enable -Wunused:explicits,implicits"),
184+
ChoiceWithHelp("linted", "Enable -Wunused:imports,privates,locals,implicits"),
185+
ChoiceWithHelp(
186+
name = "strict-no-implicit-warn",
187+
description = "Same as -Wunused:import, only for imports of explicit named members.\n" +
188+
"NOTE : This overrides -Wunused:imports and NOT set by -Wunused:all"
189+
),
190+
// ChoiceWithHelp("patvars","Warn if a variable bound in a pattern is unused"),
191+
ChoiceWithHelp(
192+
name = "unsafe-warn-patvars",
193+
description = "(UNSAFE) Warn if a variable bound in a pattern is unused.\n" +
194+
"This warning can generate false positive, as warning cannot be\n" +
195+
"suppressed yet."
196+
)
196197
),
197198
default = Nil
198199
)
199200
object WunusedHas:
200201
def isChoiceSet(s: String)(using Context) = Wunused.value.pipe(us => us.contains(s))
201-
def allOr(s: String)(using Context) = Wunused.value.pipe(us => us.contains("all") || us.contains(s))
202+
def allOr(s: String)(using Context) = Wall.value || Wunused.value.pipe(us => us.contains("all") || us.contains(s))
202203
def nowarn(using Context) = allOr("nowarn")
203204

205+
// Is any choice set for -Wunused?
206+
def any(using Context): Boolean = Wunused.value.nonEmpty
207+
204208
// overrided by strict-no-implicit-warn
205209
def imports(using Context) =
206210
(allOr("imports") || allOr("linted")) && !(strictNoImplicitWarn)
@@ -296,7 +300,17 @@ private sealed trait WarningSettings:
296300
def typeParameterShadow(using Context) =
297301
allOr("type-parameter-shadow")
298302

299-
val WcheckInit: Setting[Boolean] = BooleanSetting(WarningSetting, "Wsafe-init", "Ensure safe initialization of objects.")
303+
private val WcheckInit: Setting[Boolean] = BooleanSetting(WarningSetting, "Wsafe-init", "Ensure safe initialization of objects.")
304+
305+
object Whas:
306+
def allOr(s: Setting[Boolean])(using Context): Boolean =
307+
Wall.value || s.value
308+
def valueDiscard(using Context): Boolean = allOr(WvalueDiscard)
309+
def nonUnitStatement(using Context): Boolean = allOr(WNonUnitStatement)
310+
def enumCommentDiscard(using Context): Boolean = allOr(WenumCommentDiscard)
311+
def implausiblePatterns(using Context): Boolean = allOr(WimplausiblePatterns)
312+
def unstableInlineAccessors(using Context): Boolean = allOr(WunstableInlineAccessors)
313+
def checkInit(using Context): Boolean = allOr(WcheckInit)
300314

301315
/** -X "Extended" or "Advanced" settings */
302316
private sealed trait XSettings:

Diff for: compiler/src/dotty/tools/dotc/core/Symbols.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ object Symbols extends SymUtils {
8484
ctx.settings.YretainTrees.value ||
8585
denot.owner.isTerm || // no risk of leaking memory after a run for these
8686
denot.isOneOf(InlineOrProxy) || // need to keep inline info
87-
ctx.settings.WcheckInit.value || // initialization check
87+
ctx.settings.Whas.checkInit || // initialization check
8888
ctx.settings.YcheckInitGlobal.value
8989

9090
/** The last denotation of this symbol */

Diff for: compiler/src/dotty/tools/dotc/inlines/PrepareInlineable.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ object PrepareInlineable {
9191
postTransform(super.transform(preTransform(tree)))
9292

9393
protected def checkUnstableAccessor(accessedTree: Tree, accessor: Symbol)(using Context): Unit =
94-
if ctx.settings.WunstableInlineAccessors.value then
94+
if ctx.settings.Whas.unstableInlineAccessors then
9595
val accessorTree = accessorDef(accessor, accessedTree.symbol)
9696
report.warning(reporting.UnstableInlineAccessor(accessedTree.symbol, accessorTree), accessedTree)
9797
}

Diff for: compiler/src/dotty/tools/dotc/parsing/Parsers.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -4083,7 +4083,7 @@ object Parsers {
40834083
if (in.token == COMMA) {
40844084
in.nextToken()
40854085
val ids = commaSeparated(() => termIdent())
4086-
if ctx.settings.WenumCommentDiscard.value then
4086+
if ctx.settings.Whas.enumCommentDiscard then
40874087
in.getDocComment(start).foreach: comm =>
40884088
warning(
40894089
em"""Ambiguous Scaladoc comment on multiple cases is ignored.

Diff for: compiler/src/dotty/tools/dotc/transform/CheckUnused.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class CheckUnused private (phaseMode: CheckUnused.PhaseMode, suffix: String, _ke
5858

5959
override def isRunnable(using Context): Boolean =
6060
super.isRunnable &&
61-
ctx.settings.Wunused.value.nonEmpty &&
61+
ctx.settings.WunusedHas.any &&
6262
!ctx.isJava
6363

6464
// ========== SETUP ============

Diff for: compiler/src/dotty/tools/dotc/transform/init/Checker.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Checker extends Phase:
2929
override val runsAfter = Set(Pickler.name)
3030

3131
override def isEnabled(using Context): Boolean =
32-
super.isEnabled && (ctx.settings.WcheckInit.value || ctx.settings.YcheckInitGlobal.value)
32+
super.isEnabled && (ctx.settings.Whas.checkInit || ctx.settings.YcheckInitGlobal.value)
3333

3434
def traverse(traverser: InitTreeTraverser)(using Context): Boolean = monitor(phaseName):
3535
val unit = ctx.compilationUnit
@@ -50,7 +50,7 @@ class Checker extends Phase:
5050
cancellable {
5151
val classes = traverser.getClasses()
5252

53-
if ctx.settings.WcheckInit.value then
53+
if ctx.settings.Whas.checkInit then
5454
Semantic.checkClasses(classes)(using checkCtx)
5555

5656
if ctx.settings.YcheckInitGlobal.value then

Diff for: compiler/src/dotty/tools/dotc/typer/Linter.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ object Linter:
5555
&& !isJavaApplication(t) // Java methods are inherently side-effecting
5656
// && !treeInfo.hasExplicitUnit(t) // suppressed by explicit expr: Unit // TODO Should explicit `: Unit` be added as warning suppression?
5757

58-
if ctx.settings.WNonUnitStatement.value && !ctx.isAfterTyper && checkInterestingShapes(t) then
58+
if ctx.settings.Whas.nonUnitStatement && !ctx.isAfterTyper && checkInterestingShapes(t) then
5959
val where = t match
6060
case Block(_, res) => res
6161
case If(_, thenpart, Literal(Constant(()))) =>
@@ -119,7 +119,7 @@ object Linter:
119119
// still compute `canEqual(A & B, B & A) = true`.
120120
canEqual(a, b.tp1) || canEqual(a, b.tp2)
121121

122-
if ctx.settings.WimplausiblePatterns.value && !canEqual(pat.tpe, selType) then
122+
if ctx.settings.Whas.implausiblePatterns && !canEqual(pat.tpe, selType) then
123123
report.warning(ImplausiblePatternWarning(pat, selType), pat.srcPos)
124124
end warnOnImplausiblePattern
125125

Diff for: compiler/src/dotty/tools/dotc/typer/Typer.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -4478,7 +4478,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
44784478
// so will take the code path that decides on inlining
44794479
val tree1 = adapt(tree, WildcardType, locked)
44804480
checkStatementPurity(tree1)(tree, ctx.owner, isUnitExpr = true)
4481-
if (!ctx.isAfterTyper && !tree.isInstanceOf[Inlined] && ctx.settings.WvalueDiscard.value && !isThisTypeResult(tree)) {
4481+
if (!ctx.isAfterTyper && !tree.isInstanceOf[Inlined] && ctx.settings.Whas.valueDiscard && !isThisTypeResult(tree)) {
44824482
report.warning(ValueDiscarding(tree.tpe), tree.srcPos)
44834483
}
44844484
return tpd.Block(tree1 :: Nil, unitLiteral)

0 commit comments

Comments
 (0)