Skip to content

Option -Wall is inconsistent with -Wshadow and -Wunused #24466

@satorg

Description

@satorg

Originally confirmed on Scala Contributors.

Compiler version

v3.7.4, v3.7.nightly, v3.8.nightly.

Minimized code

//> using scala 3.7.nightly
//> using options -Wall

class A:
  protected val x: String = ""

class B extends A:
  private val x: Int = 0

Output

-- [E198] Unused Symbol Warning: .../wall-wshadow-wunused.scala:8:14 
8 |  private val x: Int = 0
  |              ^
  |              unused private member
1 warning found

Expectation

According to scala-cli -S 3.7.nightly -O -W:

  • -Wall Enable all warning settings.
  • -Wshadow Enable or disable specific shadow warnings
  • -Wunused Enable or disable specific unused warnings

It may seem that -Wall should imply both -Wshadow:all and -Wunused:all.
However for now it imlplies -Wunused only but not -Wshadow.

Therefore, when -Wshadow:all and -Wunused:all are used instead of -Wall:

//> using scala 3.7.nightly
//> using options -Wshadow:all -Wunused:all

class A:
  protected val x: String = ""

class B extends A:
  private val x: Int = 0

then the output is:

-- Warning: .../wall-wshadow-wunused.scala:8:2 
8 |  private val x: Int = 0
  |  ^
  |  value x in class B shadows field x inherited from class A
-- [E198] Unused Symbol Warning: .../wall-wshadow-wunused.scala:8:14 
8 |  private val x: Int = 0
  |              ^
  |              unused private member
2 warnings found

Metadata

Metadata

Assignees

Labels

area:lintingLinting warnings enabled with -W or -Xlintitype:bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions