Skip to content

Conversation

zuevmaxim
Copy link

Fixes #1747

The bytecode for the test method

private final int whenBoolean(boolean);
    descriptor: (Z)I
    flags: (0x0012) ACC_PRIVATE, ACC_FINAL
    Code:
      stack=2, locals=3, args_size=2
         0: iload_1
         1: istore_2
         2: iload_2
         3: iconst_1
         4: if_icmpne     11
         7: iconst_1
         8: goto          27
        11: iload_2
        12: ifne          19 // IFNE instead of IFQE HERE
        15: iconst_2
        16: goto          27
        19: new           #18                 // class kotlin/NoWhenBranchMatchedException
        22: dup
        23: invokespecial #19                 // Method kotlin/NoWhenBranchMatchedException."<init>":()V
        26: athrow
        27: ireturn

@Godin Godin self-requested a review October 17, 2024 08:15
@Godin Godin self-assigned this Oct 17, 2024
@Godin
Copy link
Member

Godin commented Oct 17, 2024

First of all thank you for your contribution! ❤️


Similar when expression with Boolean where false comes first

fun whenBoolean(p: Boolean) = when (p) {
    false -> "f"
    true -> "t"
}

produces following bytecode

         0: iload_0
         1: istore_1
         2: iload_1
         3: ifne          11
         6: ldc           #9                  // String f
         8: goto          29
        11: iload_1
        12: iconst_1
        13: if_icmpne     21
        16: ldc           #11                 // String t
        18: goto          29
        21: new           #13                 // class kotlin/NoWhenBranchMatchedException
        24: dup
        25: invokespecial #17                 // Method kotlin/NoWhenBranchMatchedException."<init>":()V
        28: athrow
        29: areturn

which is slightly different - if_icmpne instead of ifne 😉

So let's supersede this PR by #1756 , which resolves more cases.

@Godin Godin closed this Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When expression is not covered for the logical type in Kotlin
2 participants