Skip to content
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

Update KotlinUnsafeCastOperatorFilter for Kotlin 1.6 #1266

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 added this to Awaiting triage in Filtering via automation Dec 22, 2021
@Godin Godin added this to Implementation in Current work items via automation Dec 22, 2021
@Godin Godin self-assigned this Dec 22, 2021
@Godin Godin moved this from Awaiting triage to In Progress in Filtering Dec 22, 2021
Co-authored-by: Evgeny Mandrikov <mandrikov@gmail.com>
Co-authored-by: Lukas Rössler <lukas.roessler@mysugr.com>
@Godin Godin merged commit 2036acc into master Dec 22, 2021
Filtering automation moved this from In Progress to Done Dec 22, 2021
Current work items automation moved this from Implementation to Done Dec 22, 2021
@Godin Godin deleted the kotlin_unsafe_cast branch December 22, 2021 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Filtering
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

1 participant