Back to Intellij Community

AssignedValueIsNeverRead

plugins/kotlin/code-insight/descriptions/resources-en/inspectionDescriptions/AssignedValueIsNeverRead.html

2025.3-rc-2689 B
Original Source

Reports assignments where a value is assigned but never used later in the code.

Example:

fun foo(): Int = 42

  fun example() {
      var local = 0
      print(local)
      local = foo() // Assigned value is never read
  }
  • After the quick fix, the assignment is deleted:
fun foo(): Int = 42

  fun example() {
      var local = 0
      print(local)
  }
  • If the right-hand side (RHS) expression may have side effects, the quick fix will also suggest keeping the RHS expression to preserve those side effects:
fun foo(): Int = 42

  fun example() {
      var local = 0
      print(local)
      foo() // The function call is kept for its side effects
  }