Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,16 @@ private sealed trait WarningSettings:
)

object WshadowHas:
def allOr(s: String)(using Context) =
Wshadow.value.pipe(us => us.contains("all") || us.contains(s))
// Is any choice set for -Wshadow?
def any(using Context): Boolean = Wall.value || Wshadow.value.nonEmpty

def allOr(s: String)(using Context): Boolean =
Wall.value || Wshadow.value.pipe(us => us.contains("all") || us.contains(s))
def privateShadow(using Context) =
allOr("private-shadow")
def typeParameterShadow(using Context) =
allOr("type-parameter-shadow")
end WshadowHas

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

Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/CheckShadowing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ class CheckShadowing extends MiniPhase:

override def description: String = CheckShadowing.description

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

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

override def prepareForUnit(tree: tpd.Tree)(using Context): Context =
val data = ShadowingData()
Expand Down
7 changes: 7 additions & 0 deletions tests/warn/i24466.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//> using options -Wall

class A:
protected val x: String = ""

class B extends A:
private val x: Int = 0 // warn // warn unused and shadowing
Loading