JVM: add tests fixed by the last two commits
One was broken on JVM, the other on JVM_IR.
This commit is contained in:
Vendored
+55
@@ -0,0 +1,55 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
// WITH_REFLECT
|
||||||
|
// WITH_COROUTINES
|
||||||
|
// TARGET_BACKEND: JVM
|
||||||
|
// NO_CHECK_LAMBDA_INLINING
|
||||||
|
// FILE: inlined.kt
|
||||||
|
package flow
|
||||||
|
|
||||||
|
interface Flow<T> {
|
||||||
|
suspend fun collect(collector: FlowCollector<T>)
|
||||||
|
}
|
||||||
|
|
||||||
|
interface FlowCollector<T> {
|
||||||
|
suspend fun emit(value: T)
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <T> flow(crossinline body: suspend FlowCollector<T>.() -> Unit): Flow<T> =
|
||||||
|
object : Flow<T> {
|
||||||
|
override suspend fun collect(collector: FlowCollector<T>) = collector.body()
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend inline fun <T> Flow<T>.collect(crossinline body: suspend (T) -> Unit) =
|
||||||
|
collect(object : FlowCollector<T> {
|
||||||
|
override suspend fun emit(value: T) = body(value)
|
||||||
|
})
|
||||||
|
|
||||||
|
inline fun <T, R> Flow<T>.transform(crossinline transformer: suspend FlowCollector<R>.(value: T) -> Unit): Flow<R> =
|
||||||
|
flow<R> { collect { value -> transformer(value) } }
|
||||||
|
|
||||||
|
inline fun <T, R> Flow<T>.map(crossinline transformer: suspend (value: T) -> R): Flow<R> =
|
||||||
|
transform { value -> emit(transformer(value)) }
|
||||||
|
|
||||||
|
// FILE: box.kt
|
||||||
|
import flow.*
|
||||||
|
import helpers.*
|
||||||
|
import kotlin.reflect.*
|
||||||
|
import kotlin.reflect.jvm.*
|
||||||
|
import kotlin.coroutines.*
|
||||||
|
import kotlin.coroutines.intrinsics.*
|
||||||
|
|
||||||
|
suspend fun addK(x: String): String = suspendCoroutineUninterceptedOrReturn { cont ->
|
||||||
|
cont.resume(x + "K")
|
||||||
|
COROUTINE_SUSPENDED
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = ""
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
suspend {
|
||||||
|
val source = flow<String> { emit("O") }
|
||||||
|
val reference: (suspend (String) -> String) -> Flow<String> = source::map
|
||||||
|
((reference as KFunction<*>).javaMethod!!.invoke(null, source, ::addK) as Flow<String>).collect { result = it }
|
||||||
|
}.startCoroutine(EmptyContinuation)
|
||||||
|
return result
|
||||||
|
}
|
||||||
Vendored
+37
@@ -0,0 +1,37 @@
|
|||||||
|
// WITH_RUNTIME
|
||||||
|
// WITH_REFLECT
|
||||||
|
// WITH_COROUTINES
|
||||||
|
// TARGET_BACKEND: JVM
|
||||||
|
// NO_CHECK_LAMBDA_INLINING
|
||||||
|
// FILE: inlined.kt
|
||||||
|
package test
|
||||||
|
|
||||||
|
interface SuspendRunnable<R> {
|
||||||
|
suspend fun run(): R
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun makeKAdder(crossinline x: suspend () -> String) = object : SuspendRunnable<String> {
|
||||||
|
override suspend fun run() = run { x() } + "K"
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: box.kt
|
||||||
|
import test.*
|
||||||
|
import helpers.*
|
||||||
|
import kotlin.reflect.*
|
||||||
|
import kotlin.reflect.jvm.*
|
||||||
|
import kotlin.coroutines.*
|
||||||
|
import kotlin.coroutines.intrinsics.*
|
||||||
|
|
||||||
|
suspend fun getO(): String = suspendCoroutineUninterceptedOrReturn { cont ->
|
||||||
|
cont.resume("O")
|
||||||
|
COROUTINE_SUSPENDED
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = ""
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
suspend {
|
||||||
|
result = ((::makeKAdder as KFunction<*>).javaMethod!!.invoke(null, ::getO) as SuspendRunnable<String>).run()
|
||||||
|
}.startCoroutine(EmptyContinuation)
|
||||||
|
return result
|
||||||
|
}
|
||||||
+10
@@ -4044,6 +4044,16 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
|
|||||||
public void testSimpleNamed() throws Exception {
|
public void testSimpleNamed() throws Exception {
|
||||||
runTest("compiler/testData/codegen/boxInline/suspend/inlineUsedAsNoinline/simpleNamed.kt");
|
runTest("compiler/testData/codegen/boxInline/suspend/inlineUsedAsNoinline/simpleNamed.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("withCapturedInlineLambda.kt")
|
||||||
|
public void testWithCapturedInlineLambda() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/boxInline/suspend/inlineUsedAsNoinline/withCapturedInlineLambda.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("withCapturedInlineLambda2.kt")
|
||||||
|
public void testWithCapturedInlineLambda2() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/boxInline/suspend/inlineUsedAsNoinline/withCapturedInlineLambda2.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/boxInline/suspend/receiver")
|
@TestMetadata("compiler/testData/codegen/boxInline/suspend/receiver")
|
||||||
|
|||||||
Generated
+10
@@ -4044,6 +4044,16 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
|
|||||||
public void testSimpleNamed() throws Exception {
|
public void testSimpleNamed() throws Exception {
|
||||||
runTest("compiler/testData/codegen/boxInline/suspend/inlineUsedAsNoinline/simpleNamed.kt");
|
runTest("compiler/testData/codegen/boxInline/suspend/inlineUsedAsNoinline/simpleNamed.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("withCapturedInlineLambda.kt")
|
||||||
|
public void testWithCapturedInlineLambda() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/boxInline/suspend/inlineUsedAsNoinline/withCapturedInlineLambda.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("withCapturedInlineLambda2.kt")
|
||||||
|
public void testWithCapturedInlineLambda2() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/boxInline/suspend/inlineUsedAsNoinline/withCapturedInlineLambda2.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/boxInline/suspend/receiver")
|
@TestMetadata("compiler/testData/codegen/boxInline/suspend/receiver")
|
||||||
|
|||||||
+10
@@ -3924,6 +3924,16 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli
|
|||||||
public void testSimpleNamed() throws Exception {
|
public void testSimpleNamed() throws Exception {
|
||||||
runTest("compiler/testData/codegen/boxInline/suspend/inlineUsedAsNoinline/simpleNamed.kt");
|
runTest("compiler/testData/codegen/boxInline/suspend/inlineUsedAsNoinline/simpleNamed.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("withCapturedInlineLambda.kt")
|
||||||
|
public void testWithCapturedInlineLambda() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/boxInline/suspend/inlineUsedAsNoinline/withCapturedInlineLambda.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("withCapturedInlineLambda2.kt")
|
||||||
|
public void testWithCapturedInlineLambda2() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/boxInline/suspend/inlineUsedAsNoinline/withCapturedInlineLambda2.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/boxInline/suspend/receiver")
|
@TestMetadata("compiler/testData/codegen/boxInline/suspend/receiver")
|
||||||
|
|||||||
Generated
+10
@@ -3924,6 +3924,16 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC
|
|||||||
public void testSimpleNamed() throws Exception {
|
public void testSimpleNamed() throws Exception {
|
||||||
runTest("compiler/testData/codegen/boxInline/suspend/inlineUsedAsNoinline/simpleNamed.kt");
|
runTest("compiler/testData/codegen/boxInline/suspend/inlineUsedAsNoinline/simpleNamed.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("withCapturedInlineLambda.kt")
|
||||||
|
public void testWithCapturedInlineLambda() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/boxInline/suspend/inlineUsedAsNoinline/withCapturedInlineLambda.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("withCapturedInlineLambda2.kt")
|
||||||
|
public void testWithCapturedInlineLambda2() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/boxInline/suspend/inlineUsedAsNoinline/withCapturedInlineLambda2.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/codegen/boxInline/suspend/receiver")
|
@TestMetadata("compiler/testData/codegen/boxInline/suspend/receiver")
|
||||||
|
|||||||
Reference in New Issue
Block a user