Files
kotlin/compiler/testData/codegen/bytecodeText/coroutines/varValueConflictsWithTable.kt
Ilmir Usmanov f60787d57c Move coroutines to kotlin.coroutines package: tests
Introduce COMMON_COROUTINES_TEST directive.
Every test with this directive is run twice: one time with
language version 1.2 and kotlin.coroutines.experimental package
and the other time with language version 1.3 and kotlin.coroutines
package. Each run is a separate method: with suffixes _1_2 and _1_3
respectively.
However, since codegen of release coroutines is not supported in JS
backend, we generate only one method: with suffix _1_2.
 #KT-23362
2018-04-23 21:51:59 +03:00

49 lines
1.2 KiB
Kotlin
Vendored

// WITH_RUNTIME
// COMMON_COROUTINES_TEST
// WITH_COROUTINES
import helpers.*
// TREAT_AS_ONE_FILE
import COROUTINES_PACKAGE.*
import COROUTINES_PACKAGE.intrinsics.*
suspend fun suspendHere(): String = suspendCoroutineOrReturn { x ->
x.resume("OK")
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
val nonConstOne = 1
fun box(): String {
var result = "fail 1"
builder {
// Initialize var with Int value
for (i in 1..nonConstOne) {
if ("".length > 0) continue
}
// This variable should take the same slot as 'i' had
var s: String
// We should not spill 's' to continuation field because it's not initialized
// More precisely it contains a value of wrong type (it conflicts with contents of local var table),
// so an attempt of spilling may lead to problems on Android
if (suspendHere() == "OK") {
s = "OK"
}
else {
s = "fail 2"
}
result = s
}
return result
}
// 1 LOCALVARIABLE i I L.* 3
// 1 LOCALVARIABLE s Ljava/lang/String; L.* 3
// 0 PUTFIELD VarValueConflictsWithTableKt\$box\$1.I\$0 : I
/* 2 loads in cycle */
// 2 ILOAD 3