Skip to content

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 <[email protected]>
Co-authored-by: Lukas Rössler <[email protected]>
@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.

2 participants