E198: Unused Symbol
This warning is emitted when a symbol (variable, parameter, import, etc.) is declared but never used.
This warning helps identify dead code and potential mistakes where a value was intended to be used but was forgotten. The warning can identify various types of unused symbols:
- Unused imports
- Unused local definitions (vals, vars, defs)
- Unused parameters (explicit and implicit)
- Unused private members
- Pattern variables that are not used
This warning requires the -Wunused compiler flag with appropriate sub-options (e.g., -Wunused:all).
Example
//> using options -Wunused:all
def example(): Unit =
val unused = 42
println("hello")
Error
-- [E198] Unused Symbol Warning: example.scala:4:6 -----------------------------
4 | val unused = 42
| ^^^^^^
| unused local definition
Solution
Remove the unused symbol:
//> using options -Wunused:all
def example(): Unit =
println("hello")
Or use the symbol:
//> using options -Wunused:all
def example(): Unit =
val value = 42
println(s"The value is $value")
Or suppress the warning by using val with underscore identifier
//> using options -Wunused:all
def example(): Unit =
val _ = 42
println("hello")
In this article