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 KotlinControlStructuresTarget for Kotlin 1.5 #1180

Merged
merged 1 commit into from May 3, 2021
Merged

Conversation

Godin
Copy link
Member

@Godin Godin commented May 3, 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.KotlinControlStructuresTest): Instructions (KotlinControlStructuresTarget.kt:67) expected:<[PART]LY_COVERED> but was:<[FUL]LY_COVERED>

For the following Example.kt

fun example() {
  for (i in 0..-1) {
    nop()
  }
}

fun nop() {
}

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 void example();
    descriptor: ()V
    flags: ACC_PUBLIC, ACC_STATIC, ACC_FINAL
    Code:
      stack=2, locals=2, args_size=0
         0: iconst_0
         1: istore_0
         2: iconst_m1
         3: istore_1
         4: iload_0
         5: iload_1
         6: if_icmpgt     18
         9: invokestatic  #9                  // Method nop:()V
        12: iinc          0, 1
        15: goto          4
        18: return
      LineNumberTable:
        line 2: 0
        line 2: 4
        line 3: 9
        line 2: 12
        line 5: 18

whereas using Kotlin compiler version 1.5 produces

  public static final void example();
    descriptor: ()V
    flags: (0x0019) ACC_PUBLIC, ACC_STATIC, ACC_FINAL
    Code:
      stack=1, locals=1, args_size=0
         0: iconst_0
         1: istore_0
         2: return
      LineNumberTable:
        line 2: 0
        line 5: 2

i.e. for-loop with range expression whose bounds are constants with end less than start is folded into nop by Kotlin compiler version 1.5

Without constants in for-loops behaviour is the same for compiler version 1.5 as for earlier versions.

for-loop with range expression whose bounds are constants with end
less than start is folded into nop by Kotlin compiler version 1.5,
without constants in for-loops behaviour is the same for compiler
version 1.5 as for earlier versions.
@Godin Godin added this to the 0.8.7 milestone May 3, 2021
@Godin Godin self-assigned this May 3, 2021
@Godin Godin added this to Implementation in Current work items via automation May 3, 2021
@Godin Godin marked this pull request as ready for review May 3, 2021 11:05
@Godin Godin moved this from Implementation to Review in Current work items May 3, 2021
@Godin Godin requested a review from marchof May 3, 2021 11:05
@marchof marchof merged commit 29a2890 into master May 3, 2021
Current work items automation moved this from Review to Done May 3, 2021
@marchof marchof deleted the kotlin_for_loop branch May 3, 2021 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants