Back to Intellij Community

RedundantWith

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

2025.3-rc-2420 B
Original Source

Reports redundant with function calls that don't access anything from the receiver.

Examples:

class MyClass {
      fun f(): String = ""
  }

  fun testRedundant() {
      with(c) { // <== 'with' is redundant since 'c' isn't used
          println("1")
      }
  }

  fun testOk() {
      val c = MyClass()
      with(c) { // <== OK because 'f()' is effectively 'c.f()'
          println(f())
      }
  }