6

This code compiles successfully with Kotlin 1.2.10, but when I run it it produces a java.lang.VerifyError: Bad type on operand stack. If I remove the Test class and extract the functions out, it works as expected. Why is that?

import kotlinx.coroutines.experimental.delay
import kotlinx.coroutines.experimental.launch
import kotlinx.coroutines.experimental.runBlocking
import java.util.*
import kotlin.concurrent.schedule

class Test {
    fun scheduleTimeout() {
        Timer(true).schedule(300) {
            launch {
                runSuspended("hello")
            }
        }
    }

    suspend fun runSuspended(txt: String) = println(txt)
}

fun main(args: Array<String>) {
    Test().scheduleTimeout()
    runBlocking {
        delay(10000)
    }
}

Full Exception:

Exception in thread "Timer-0" java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    Test$scheduleTimeout$$inlined$schedule$1$lambda$1.create(Lkotlinx/coroutines/experimental/CoroutineScope;Lkotlin/coroutines/experimental/Continuation;)Lkotlin/coroutines/experimental/Continuation; @18: invokespecial
  Reason:
    Type 'Test$scheduleTimeout$$inlined$schedule$1$lambda$1' (current frame, stack[3]) is not assignable to 'Test$scheduleTimeout$$inlined$schedule$1'
  Current Frame:
    bci: @18
    flags: { }
    locals: { 'Test$scheduleTimeout$$inlined$schedule$1$lambda$1', 'kotlinx/coroutines/experimental/CoroutineScope', 'kotlin/coroutines/experimental/Continuation' }
    stack: { uninitialized 12, uninitialized 12, 'kotlin/coroutines/experimental/Continuation', 'Test$scheduleTimeout$$inlined$schedule$1$lambda$1' }
  Bytecode:
    0x0000000: 2b12 64b8 006a 2c12 6cb8 006a bb00 0259
    0x0000010: 2c2a b700 6e4e 2d2b b500 3d2d 3a04 1904
    0x0000020: b0                                     

    at Test$scheduleTimeout$$inlined$schedule$1.run(Timer.kt:145)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)
3
  • 1
    I don't know if you saw it, but your same question on the Kotlin Slack eventually got answered: this is a bug, and you should file it in YouTrack. Just passing this along in case you didn't see it, l had nothing to do with the answer.
    – Todd
    Jan 1, 2018 at 19:56
  • 2
    I reported it: youtrack.jetbrains.com/issue/KT-22081
    – andresp
    Jan 1, 2018 at 21:27
  • 1
    I tested this with Kotlin 1.2.61 and it now works properly. It has reportedly been fixed in 1.2.40.
    – andresp
    Aug 27, 2018 at 13:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.