[JVM IR] Fix issue with suspend functions with @JvmOverloads.
This commit is contained in:
committed by
Ilmir Usmanov
parent
c289612e57
commit
3d51af2935
+2
@@ -116,6 +116,8 @@ internal fun IrFunction.isInvokeOfSuspendCallableReference(): Boolean = isSuspen
|
||||
internal fun IrFunction.isKnownToBeTailCall(): Boolean =
|
||||
when (origin) {
|
||||
IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER,
|
||||
JvmLoweredDeclarationOrigin.JVM_OVERLOADS_WRAPPER,
|
||||
JvmLoweredDeclarationOrigin.MULTIFILE_BRIDGE,
|
||||
JvmLoweredDeclarationOrigin.SYNTHETIC_ACCESSOR,
|
||||
JvmLoweredDeclarationOrigin.DEFAULT_IMPLS_BRIDGE,
|
||||
JvmLoweredDeclarationOrigin.DEFAULT_IMPLS_BRIDGE_TO_SYNTHETIC,
|
||||
|
||||
-2
@@ -142,8 +142,6 @@ open class FunctionCodegen(
|
||||
origin != IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA &&
|
||||
// This is just a template for inliner
|
||||
origin != JvmLoweredDeclarationOrigin.FOR_INLINE_STATE_MACHINE_TEMPLATE_CAPTURES_CROSSINLINE &&
|
||||
// This is just a bridge to the function with the continuation
|
||||
origin != JvmLoweredDeclarationOrigin.MULTIFILE_BRIDGE &&
|
||||
// Continuations are generated for suspendImpls
|
||||
parentAsClass.functions.none {
|
||||
it.name.asString() == name.asString() + SUSPEND_IMPL_NAME_SUFFIX &&
|
||||
|
||||
+2
-1
@@ -652,7 +652,8 @@ private class AddContinuationLowering(private val context: JvmBackendContext) :
|
||||
function.parentAsClass.origin == JvmLoweredDeclarationOrigin.FUNCTION_REFERENCE_IMPL ||
|
||||
function.origin == IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER ||
|
||||
function.origin == JvmLoweredDeclarationOrigin.GENERATED_MEMBER_IN_CALLABLE_REFERENCE ||
|
||||
function.origin == JvmLoweredDeclarationOrigin.DEFAULT_IMPLS_BRIDGE
|
||||
function.origin == JvmLoweredDeclarationOrigin.DEFAULT_IMPLS_BRIDGE ||
|
||||
function.origin == JvmLoweredDeclarationOrigin.JVM_OVERLOADS_WRAPPER
|
||||
|
||||
private fun skip(function: IrFunction) =
|
||||
!function.isSuspend ||
|
||||
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
// WITH_RUNTIME
|
||||
// WITH_COROUTINES
|
||||
|
||||
// FILE: defaultParametersInSuspsendWithJvmOverloads.kt
|
||||
import helpers.*
|
||||
import kotlin.coroutines.*
|
||||
import kotlin.coroutines.intrinsics.*
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@JvmOverloads
|
||||
suspend fun suspendHere(a: String = "abc", i: Int = 2): String = suspendCoroutineUninterceptedOrReturn { x ->
|
||||
x.resume(a + "#" + (i + 1))
|
||||
COROUTINE_SUSPENDED
|
||||
}
|
||||
|
||||
fun builder(c: suspend () -> Unit) {
|
||||
c.startCoroutine(EmptyContinuation)
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
assertEquals(listOf("abc#3", "cde#3", "xyz#10"), J().foo())
|
||||
|
||||
val result = mutableListOf<String>()
|
||||
builder {
|
||||
result.add(suspendHere())
|
||||
result.add(suspendHere("cde"))
|
||||
result.add(suspendHere(i = 6))
|
||||
result.add(suspendHere("xyz", 9))
|
||||
}
|
||||
assertEquals(listOf("abc#3", "cde#3", "abc#7", "xyz#10"), result)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
// FILE: J.java
|
||||
import java.util.*;
|
||||
import kotlin.coroutines.*;
|
||||
|
||||
public class J {
|
||||
private List<String> result = new ArrayList<>();
|
||||
|
||||
public List<String> foo() {
|
||||
MyContinuation continuation = new MyContinuation();
|
||||
DefaultParametersInSuspsendWithJvmOverloadsKt.suspendHere(continuation);
|
||||
DefaultParametersInSuspsendWithJvmOverloadsKt.suspendHere("cde", continuation);
|
||||
DefaultParametersInSuspsendWithJvmOverloadsKt.suspendHere("xyz", 9, continuation);
|
||||
return result;
|
||||
}
|
||||
|
||||
private class MyContinuation implements Continuation<String> {
|
||||
@Override
|
||||
public CoroutineContext getContext() {
|
||||
return EmptyCoroutineContext.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resumeWith(Object x) {
|
||||
result.add((String) x);
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
@@ -6155,6 +6155,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/crossInlineWithCapturedOuterReceiver.kt", "kotlin.coroutines");
|
||||
}
|
||||
|
||||
@TestMetadata("defaultParametersInSuspendWithJvmOverloads.kt")
|
||||
public void testDefaultParametersInSuspendWithJvmOverloads() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/coroutines/defaultParametersInSuspendWithJvmOverloads.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("defaultParametersInSuspend.kt")
|
||||
public void testDefaultParametersInSuspend_1_2() throws Exception {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/defaultParametersInSuspend.kt", "kotlin.coroutines.experimental");
|
||||
|
||||
+5
@@ -6155,6 +6155,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/crossInlineWithCapturedOuterReceiver.kt", "kotlin.coroutines");
|
||||
}
|
||||
|
||||
@TestMetadata("defaultParametersInSuspendWithJvmOverloads.kt")
|
||||
public void testDefaultParametersInSuspendWithJvmOverloads() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/coroutines/defaultParametersInSuspendWithJvmOverloads.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("defaultParametersInSuspend.kt")
|
||||
public void testDefaultParametersInSuspend_1_2() throws Exception {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/defaultParametersInSuspend.kt", "kotlin.coroutines.experimental");
|
||||
|
||||
+5
@@ -6055,6 +6055,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/crossInlineWithCapturedOuterReceiver.kt", "kotlin.coroutines");
|
||||
}
|
||||
|
||||
@TestMetadata("defaultParametersInSuspendWithJvmOverloads.kt")
|
||||
public void testDefaultParametersInSuspendWithJvmOverloads() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/coroutines/defaultParametersInSuspendWithJvmOverloads.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("defaultParametersInSuspend.kt")
|
||||
public void testDefaultParametersInSuspend_1_3() throws Exception {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/defaultParametersInSuspend.kt", "kotlin.coroutines");
|
||||
|
||||
+5
@@ -6055,6 +6055,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/crossInlineWithCapturedOuterReceiver.kt", "kotlin.coroutines");
|
||||
}
|
||||
|
||||
@TestMetadata("defaultParametersInSuspendWithJvmOverloads.kt")
|
||||
public void testDefaultParametersInSuspendWithJvmOverloads() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/coroutines/defaultParametersInSuspendWithJvmOverloads.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("defaultParametersInSuspend.kt")
|
||||
public void testDefaultParametersInSuspend_1_3() throws Exception {
|
||||
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/defaultParametersInSuspend.kt", "kotlin.coroutines");
|
||||
|
||||
Reference in New Issue
Block a user