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.5 #1178

Merged
merged 3 commits into from Apr 30, 2021

Conversation

Godin
Copy link
Member

@Godin Godin commented Apr 30, 2021

Currently execution of any of

mvn clean package -Dkotlin.version=1.5.0-M1
mvn clean package -Dkotlin.version=1.5.0-M2
mvn clean package -Dkotlin.version=1.5.0-RC
mvn clean package -Dkotlin.version=1.5.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.4 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=4, locals=1, args_size=1
         0: aload_0
         1: dup
         2: ifnonnull     15
         5: new           #10                 // class java/lang/NullPointerException
         8: dup
         9: ldc           #12                 // String null cannot be cast to non-null type kotlin.String
        11: invokespecial #16                 // Method java/lang/NullPointerException."<init>":(Ljava/lang/String;)V
        14: athrow
        15: areturn

whereas using Kotlin compiler version 1.5 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

and so there is relation with comment that I made in #1143 (comment)
unfortunately bytecode generated by 1.5 is the same as bytecode that both versions generate for

fun f(s: String?): String {
  if (s == null)
    throw NullPointerException("null cannot be cast to non-null type kotlin.String")
  return s
}

@Godin Godin added this to the 0.8.7 milestone Apr 30, 2021
@Godin Godin self-assigned this Apr 30, 2021
@Godin Godin added this to Implementation in Current work items via automation Apr 30, 2021
@Godin Godin marked this pull request as ready for review April 30, 2021 09:44
@Godin Godin requested a review from marchof April 30, 2021 09:44
@Godin Godin moved this from Implementation to Review in Current work items Apr 30, 2021
@marchof marchof merged commit b23461d into master Apr 30, 2021
Current work items automation moved this from Review to Done Apr 30, 2021
@marchof marchof deleted the kotlin_unsafe_cast branch April 30, 2021 10:05
@Godin Godin added this to To Do in Filtering via automation May 4, 2021
@Godin Godin moved this from To Do to Done in Filtering May 4, 2021
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

2 participants