Skip to content

Commit cad0d2a

Browse files
authored
Wshadow option recognizes Wall (#24469)
Fixes #24466
2 parents 73bbcfe + 1e5b591 commit cad0d2a

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,16 @@ private sealed trait WarningSettings:
290290
)
291291

292292
object WshadowHas:
293-
def allOr(s: String)(using Context) =
294-
Wshadow.value.pipe(us => us.contains("all") || us.contains(s))
293+
// Is any choice set for -Wshadow?
294+
def any(using Context): Boolean = Wall.value || Wshadow.value.nonEmpty
295+
296+
def allOr(s: String)(using Context): Boolean =
297+
Wall.value || Wshadow.value.pipe(us => us.contains("all") || us.contains(s))
295298
def privateShadow(using Context) =
296299
allOr("private-shadow")
297300
def typeParameterShadow(using Context) =
298301
allOr("type-parameter-shadow")
302+
end WshadowHas
299303

300304
val WsafeInit: Setting[Boolean] = BooleanSetting(WarningSetting, "Wsafe-init", "Ensure safe initialization of objects.")
301305

compiler/src/dotty/tools/dotc/transform/CheckShadowing.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ class CheckShadowing extends MiniPhase:
4848

4949
override def description: String = CheckShadowing.description
5050

51-
override def isEnabled(using Context): Boolean = ctx.settings.Wshadow.value.nonEmpty
51+
override def isEnabled(using Context): Boolean = ctx.settings.WshadowHas.any
5252

5353
override def isRunnable(using Context): Boolean =
54-
super.isRunnable && ctx.settings.Wshadow.value.nonEmpty && !ctx.isJava
54+
super.isRunnable && ctx.settings.WshadowHas.any && !ctx.isJava
5555

5656
override def prepareForUnit(tree: tpd.Tree)(using Context): Context =
5757
val data = ShadowingData()

tests/warn/i24466.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
//> using options -Wall
2+
3+
class A:
4+
protected val x: String = ""
5+
6+
class B extends A:
7+
private val x: Int = 0 // warn // warn unused and shadowing

0 commit comments

Comments
 (0)