Support loading function types

This commit is contained in:
Ilmir Usmanov
2018-07-05 21:00:38 +03:00
parent 5b7e099842
commit dbc3ddc578
3 changed files with 38 additions and 1 deletions
@@ -0,0 +1,32 @@
// FILE: A.kt
// LANGUAGE_VERSION: 1.2
import kotlin.coroutines.experimental.*
fun builder(c: suspend () -> String): String {
var res = "FAIL"
c.startCoroutine(object : Continuation<String> {
override val context = EmptyCoroutineContext
override fun resume(value: String) {
res = value
}
override fun resumeWithException(exception: Throwable) {
throw exception
}
})
return res
}
// FILE: B.kt
// LANGUAGE_VERSION: 1.3
import kotlin.coroutines.experimental.*
fun ok(continuation: Continuation<String>): Any? {
return "OK"
}
fun box(): String {
if (builder(::ok) != "OK") return "FAIL 1"
if (builder { cont: Continuation<String> -> "OK" } != "OK") return "FAIL 2"
if (builder(fun (cont: Continuation<String>): Any? = "OK") != "OK") return "FAIL 2"
return "OK"
}
@@ -290,6 +290,11 @@ public class CompileKotlinAgainstKotlinTestGenerated extends AbstractCompileKotl
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/compileKotlinAgainstKotlin/coroutines"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("builder.kt")
public void testBuilder() throws Exception {
runTest("compiler/testData/compileKotlinAgainstKotlin/coroutines/builder.kt");
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("compiler/testData/compileKotlinAgainstKotlin/coroutines/simple.kt");
@@ -89,7 +89,7 @@ fun transformRuntimeFunctionTypeToSuspendFunction(funType: KotlinType, isRelease
if (!isContinuation(continuationArgumentType.constructor.declarationDescriptor?.fqNameSafe, isReleaseCoroutines) ||
continuationArgumentType.arguments.size != 1
) {
return null
return funType as? SimpleType
}
val suspendReturnType = continuationArgumentType.arguments.single().type