Skip to content

In Kotlin safe call operator followed by elvis operator should be filtered #1814

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Godin
Copy link
Member

@Godin Godin commented Dec 12, 2024

Requires


For the following Example.kt

data class B(val c: String)
fun example(b: B?): String =
    b?.c ?: ""

Kotlin compiler generates

  public static final java.lang.String example(B);
    descriptor: (LB;)Ljava/lang/String;
    flags: (0x0019) ACC_PUBLIC, ACC_STATIC, ACC_FINAL
    Code:
      stack=2, locals=1, args_size=1
         0: aload_0
         1: dup
         2: ifnull        12
         5: invokevirtual #14                 // Method B.getC:()Ljava/lang/String;
         8: dup
         9: ifnonnull     15
        12: pop
        13: ldc           #16                 // String
        15: areturn

To be able to achieve full coverage branches of ifnull and ifnonnull instructions should be replaced as following

non-null case should be considered covered when

  • branch 1 of ifnonnull instruction was executed

There is no instruction whose execution status allows to determine that only non-null case was executed, so the current replaceBranches is not usable and that's why #1813 is required.

null case should be considered covered when

  • branch 1 of ifnull instruction was executed
  • or branch 0 of ifnonnull instruction was executed

Fixes #1351

@Godin Godin self-assigned this Dec 12, 2024
@Godin Godin force-pushed the kotlin_safe_call_followed_by_elvis branch 2 times, most recently from 2599863 to f3887ba Compare December 16, 2024 23:01
@Godin Godin added this to the 0.8.13 milestone Dec 16, 2024
@Godin Godin force-pushed the kotlin_safe_call_followed_by_elvis branch from f3887ba to aa9fdb4 Compare January 6, 2025 10:22
@Godin Godin modified the milestones: 0.8.13, 0.8.14 Apr 1, 2025
@Godin Godin force-pushed the kotlin_safe_call_followed_by_elvis branch 3 times, most recently from 530b10d to c89833d Compare April 15, 2025 21:15
@Godin Godin force-pushed the kotlin_safe_call_followed_by_elvis branch from c89833d to 470e707 Compare April 15, 2025 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

Missing branch reported for safe call/elvis operator statement, but only only later versions of Kotlin
1 participant