Allow generic decomposition on conditionnal control flow


I have realize that objects than can be decomposed (i.e. Pair, Iterable) cannot be mixed into a condition wrapper because conditions returns Any type. Even if the two object can be wrap into a destructuring declaration.

Example of code :

data class TwoString(val str1: String, val str2: String)

object Default {
    operator fun component1() = "Default1"
    operator fun component2() = "Default2"

fun foo(){
    //work fine
    val (foo1, bar1) = TwoString("", "")
    val (foo2, bar2) = Default
    val (foo3, bar3) = listOf("", "")

    //doesn't work
    val (foo4, bar4) = if (condition) listOf("", "") else TwoString("", "")
    val (foo5, bar5) = if (condition) listOf("", "") else Default
    val (foo6, bar6) = if (condition) Default else TwoString("", "")
    val (foo7, bar7) = when {
        condition1 -> TwoString("", "")
        condition2 -> listOf("", "")
        else -> Default