Skip to content

Update KotlinUnsafeCastOperatorFilter for Kotlin 1.6 #1266

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

Merged
merged 3 commits into from
Dec 22, 2021
Merged

Conversation

Godin
Copy link
Member

@Godin Godin commented Dec 22, 2021

Currently execution of

mvn clean package -Dkotlin.version=1.6.0

leads to

Failed tests:
  execute_assertions_in_comments(org.jacoco.core.test.validation.kotlin.KotlinUnsafeCastOperatorTest): Instructions (KotlinUnsafeCastOperatorTarget.kt:26) expected:<[FUL]LY_COVERED> but was:<[PART]LY_COVERED>

For the following Example.kt

fun f(s: String?): String {
  return s as String
}

execution of

kotlin/bin/kotlinc Example.kt -d classes
javap -v -p classes/ExampleKt.class

using Kotlin compiler version 1.5.32 (latest as of today in 1.5 series) produces

  public static final java.lang.String f(java.lang.String);
    descriptor: (Ljava/lang/String;)Ljava/lang/String;
    flags: (0x0019) ACC_PUBLIC, ACC_STATIC, ACC_FINAL
    Code:
      stack=3, locals=1, args_size=1
         0: aload_0
         1: ifnonnull     14
         4: new           #10                 // class java/lang/NullPointerException
         7: dup
         8: ldc           #12                 // String null cannot be cast to non-null type kotlin.String
        10: invokespecial #16                 // Method java/lang/NullPointerException."<init>":(Ljava/lang/String;)V
        13: athrow
        14: aload_0
        15: areturn

whereas using Kotlin compiler version 1.6.0 produces

  public static final java.lang.String f(java.lang.String);
    descriptor: (Ljava/lang/String;)Ljava/lang/String;
    flags: (0x0019) ACC_PUBLIC, ACC_STATIC, ACC_FINAL
    Code:
      stack=3, locals=1, args_size=1
         0: aload_0
         1: dup
         2: ifnonnull     16
         5: pop
         6: new           #10                 // class java/lang/NullPointerException
         9: dup
        10: ldc           #12                 // String null cannot be cast to non-null type kotlin.String
        12: invokespecial #16                 // Method java/lang/NullPointerException."<init>":(Ljava/lang/String;)V
        15: athrow
        16: areturn

This relates to the following change in Kotlin compiler - JetBrains/kotlin@041773f#diff-c479e51c961b3189024716a2e505117e50c2f05b630be1ea40ec70304a34f16aR250-R331


Closes #1255

@Godin Godin added this to the 0.8.8 milestone Dec 22, 2021
@Godin Godin self-assigned this Dec 22, 2021
@Godin Godin force-pushed the kotlin_unsafe_cast branch from fbab8e7 to 081801f Compare December 22, 2021 00:42
Co-authored-by: Evgeny Mandrikov <mandrikov@gmail.com>
Co-authored-by: Lukas Rössler <lukas.roessler@mysugr.com>
@Godin Godin force-pushed the kotlin_unsafe_cast branch from 5ae3ad4 to 2e27ddd Compare December 22, 2021 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant