Unused Local Variable
ID |
kotlin.unused_local_variable |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Code Smell |
Language |
Kotlin |
Tags |
CWE:563, unused-code |
Description
Reports function-local val / var declarations whose name is never read
in the enclosing function or lambda body. An unread local stores a value
no consumer uses; the declaration is dead state.
Rationale
fun example(): Int {
val temp = 42 // FLAW — never read
return 0
}
fun used(): Int {
val v = 42 // OK — used below
return v + 1
}
Local variables that are written but never read indicate either an incomplete refactor (the consumer was removed but the producer remained) or confusion about the value’s purpose. In either case, the declaration adds noise without benefit.