Add tests for issues fixed in JVM IR and other obsolete issues

#KT-6007
 #KT-16445
 #KT-17753
 #KT-22488
 #KT-23881
 #KT-24135
 #KT-26360
 #KT-27427
 #KT-27449
 #KT-27830
 #KT-28042
 #KT-29595
 #KT-30708
 #KT-32793
This commit is contained in:
Alexander Udalov
2021-01-07 19:31:59 +01:00
parent 3e59adc7f3
commit 5480faf5c5
36 changed files with 824 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND: JVM
// WITH_RUNTIME
class ShouldBeCaptured
class ShouldNOTBeCaptured
class ClassWithCallback {
var someCallback: (() -> Unit)? = null
fun checkFields(): String {
for (field in someCallback!!.javaClass.declaredFields) {
val value = field.get(someCallback!!)
if (value is ShouldNOTBeCaptured) throw AssertionError("Leaked value")
}
return "OK"
}
}
fun box(): String {
val toCapture = ShouldBeCaptured()
val notToCapture = ShouldNOTBeCaptured()
val classWithCallback = ClassWithCallback()
classWithCallback.apply {
someCallback = { toCapture }
notToCapture
}
return classWithCallback.checkFields()
}
@@ -0,0 +1,23 @@
// IGNORE_BACKEND: JVM
// WITH_RUNTIME
// WITH_COROUTINES
// KT-27830
import helpers.EmptyContinuation
import kotlin.coroutines.*
fun box(): String {
var result = "Fail"
suspend {
do {
go {
result = "OK"
}
} while (false)
}.startCoroutine(EmptyContinuation)
return result
}
suspend inline fun go(block: suspend () -> Unit) {
block()
}
+38
View File
@@ -0,0 +1,38 @@
// IGNORE_BACKEND: JVM
// WITH_RUNTIME
// WITH_COROUTINES
import helpers.EmptyContinuation
import kotlin.coroutines.*
var result = ""
lateinit var c: Continuation<Unit>
fun builder(block: suspend () -> Unit) {
block.startCoroutine(EmptyContinuation())
}
fun box(): String {
val flow = foo {
bar()
result += "O"
}
builder {
flow()
}
c.resume(Unit)
return result
}
suspend fun bar() {
return suspendCoroutine { cont: Continuation<Unit> ->
c = cont
}
}
inline fun foo(crossinline coroutine: suspend () -> Unit): suspend () -> Unit {
return {
coroutine.invoke()
result += "K"
}
}
@@ -0,0 +1,27 @@
// IGNORE_BACKEND: JVM
// WITH_RUNTIME
// WITH_COROUTINES
// KT-27449
import helpers.EmptyContinuation
import kotlin.coroutines.*
var result = "Fail"
suspend fun doAction() {
suspend fun run(
a: String,
f: suspend (String) -> Unit = { input -> result = input }
) {
f(a)
}
run("OK")
}
fun box(): String {
suspend {
doAction()
}.startCoroutine(EmptyContinuation)
return result
}
+25
View File
@@ -0,0 +1,25 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: CALLABLE_REFERENCES_FAIL
// WITH_RUNTIME
// WITH_COROUTINES
// IGNORE_BACKEND: JVM
import kotlin.coroutines.startCoroutine
import helpers.EmptyContinuation
suspend fun test() {
suspend fun process(myValue: UInt) {
if (myValue != 42u) throw AssertionError(myValue)
}
val value: UInt = 42u
process(value)
}
fun builder(block: suspend () -> Unit) {
block.startCoroutine(EmptyContinuation)
}
fun box(): String {
builder { test() }
return "OK"
}
+11
View File
@@ -0,0 +1,11 @@
interface SomeInterface<T>
object Container {
private inline fun <reified T> someMethod() = object : SomeInterface<T> { }
class SomeClass : SomeInterface<SomeClass> by someMethod()
}
fun box(): String {
Container.SomeClass()
return "OK"
}