Back to Intellij Community

UnusedUnaryOperator

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

2025.3-rc-2473 B
Original Source

Reports unary operators for number types on unused expressions.

Unary operators break previous expression if they are used without braces. As a result, mathematical expressions spanning multi lines can be misleading.

Example:

fun main() {
      val result = 1 + 2 * 3
                  + 3 // <== note that '+ 3' doesn't belong to the 'result' variable, it is unused
      println("Result = $result") // The result is '7' and not '10' as it might be expected
  }