Back to Intellij Community

CustomComponentDestructuringMigration

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

2025.3-rc-2970 B
Original Source

Reports position-based destructuring declarations that use custom componentN functions and need to be migrated for name-based destructuring.

With new name-based destructuring enabled, parentheses (x, y) will be used for name-based destructuring, while square brackets [x, y] should be used for position-based destructuring.

The inspection warns when:

  • Destructuring a non-data-class (all components are custom)
  • Destructuring a data class with more entries than primary constructor parameters (extra components are custom)

Examples:

val (x, y) = listOf(1, 2) // warning: uses custom componentN
  for ((key, value) in mapOf(1 to "one")) { } // warning: uses custom componentN

  data class Person(val name: String, val age: Int) {
      operator fun component3(): String = name + age
  }
  val (name, age, rendered) = Person("John", 30) // warning: component3 is custom

This inspection is part of the migration plan for name-based destructuring.