此代码与Kotlin 1.2.10成功编译,但是当我运行它时会生成java.lang.VerifyError: Bad type on operand stack
。如果我删除Test
类并提取函数,它将按预期工作。那是为什么?
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)
}
}
完全例外:
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)