Pull data-class fields into separate local values.

destructuring Data classes support destructuring declarations in the order of constructor properties.

Destructuring

x
Destructuring.kt
Replay: real traced execution (multi-file project)
data class Point(val x: Int, val y: Int)

fun main() {
    val x = 3
    val point = Point(x, 4)
    val (left, top) = point
    val total = left + top

    println("left=$left")
    println("total=$total")
}
data class Point(val x: Int, val y: Int)

fun main() {
    val x = 1
    val point = Point(x, 4)
    val (left, top) = point
    val total = left + top

    println("left=$left")
    println("total=$total")
}
data class Point(val x: Int, val y: Int)

fun main() {
    val x = 5
    val point = Point(x, 4)
    val (left, top) = point
    val total = left + top

    println("left=$left")
    println("total=$total")
}
  1. x ← 3, total ← 7

    3fun main() {4    val x→ 3 = 3 //@x=1, 55    val point = Point(x3, 4)6    val (left, top) = point7    val total→ 7 = left3 + top489    println("left=$left3")10    println("total=$total7")11}
    outputleft=3
    total=7
  1. x ← 1, total ← 5

    3fun main() {4    val x→ 1 = 15    val point = Point(x1, 4)6    val (left, top) = point7    val total→ 5 = left1 + top489    println("left=$left1")10    println("total=$total5")11}
    outputleft=1
    total=5
  1. x ← 5, total ← 9

    3fun main() {4    val x→ 5 = 55    val point = Point(x5, 4)6    val (left, top) = point7    val total→ 9 = left5 + top489    println("left=$left5")10    println("total=$total9")11}
    outputleft=5
    total=9