diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 1c5a8cc668c..654a69ca648 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -20793,6 +20793,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/jvm8/defaults/superCall.kt"); } + @Test + @TestMetadata("suspendFunction.kt") + public void testSuspendFunction() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/suspendFunction.kt"); + } + @Nested @TestMetadata("compiler/testData/codegen/box/jvm8/defaults/allCompatibility") @TestDataPath("$PROJECT_ROOT") @@ -20970,6 +20976,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/simpleFunction.kt"); } + @Test + @TestMetadata("suspendFunction.kt") + public void testSuspendFunction() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/suspendFunction.kt"); + } + @Nested @TestMetadata("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/delegationBy") @TestDataPath("$PROJECT_ROOT") @@ -21292,6 +21304,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/simpleFunction.kt"); } + @Test + @TestMetadata("suspendFunction.kt") + public void testSuspendFunction() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/suspendFunction.kt"); + } + @Nested @TestMetadata("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/delegationBy") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt index b0ef3d63134..45f1a89fdeb 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/AddContinuationLowering.kt @@ -16,6 +16,7 @@ import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin import org.jetbrains.kotlin.backend.jvm.codegen.continuationParameter import org.jetbrains.kotlin.backend.jvm.codegen.hasContinuation import org.jetbrains.kotlin.backend.jvm.codegen.isInvokeSuspendOfContinuation +import org.jetbrains.kotlin.backend.jvm.codegen.isJvmInterface import org.jetbrains.kotlin.backend.jvm.ir.defaultValue import org.jetbrains.kotlin.backend.jvm.ir.isStaticInlineClassReplacement import org.jetbrains.kotlin.backend.jvm.localDeclarationsPhase @@ -302,7 +303,7 @@ private class AddContinuationLowering(context: JvmBackendContext) : SuspendLower } } - val newFunction = if (function.isOverridable) { + val newFunction = if (function.isOverridable && !function.parentAsClass.isJvmInterface) { // Create static method for the suspend state machine method so that reentering the method // does not lead to virtual dispatch to the wrong method. createStaticSuspendImpl(view).also { result += it } diff --git a/compiler/testData/codegen/box/jvm8/defaults/allCompatibility/suspendFunction.kt b/compiler/testData/codegen/box/jvm8/defaults/allCompatibility/suspendFunction.kt new file mode 100644 index 00000000000..94d968f913f --- /dev/null +++ b/compiler/testData/codegen/box/jvm8/defaults/allCompatibility/suspendFunction.kt @@ -0,0 +1,38 @@ +// !JVM_DEFAULT_MODE: all-compatibility +// TARGET_BACKEND: JVM +// IGNORE_BACKEND: JVM +// JVM_TARGET: 1.8 +// WITH_COROUTINES +// WITH_RUNTIME + +import kotlin.coroutines.* +import helpers.* + +interface S { + suspend fun foo() +} + +interface T : S { + override suspend fun foo() { + bar() + } + + fun bar() +} + +object O : T { + var result = "" + + override fun bar() { + result = "OK" + } +} + +fun builder(block: suspend () -> Unit) { + block.startCoroutine(EmptyContinuation) +} + +fun box(): String { + builder { O.foo() } + return O.result +} diff --git a/compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/suspendFunction.kt b/compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/suspendFunction.kt new file mode 100644 index 00000000000..c449e7e231a --- /dev/null +++ b/compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/suspendFunction.kt @@ -0,0 +1,37 @@ +// !JVM_DEFAULT_MODE: all +// TARGET_BACKEND: JVM +// JVM_TARGET: 1.8 +// WITH_COROUTINES +// WITH_RUNTIME + +import kotlin.coroutines.* +import helpers.* + +interface S { + suspend fun foo() +} + +interface T : S { + override suspend fun foo() { + bar() + } + + fun bar() +} + +object O : T { + var result = "" + + override fun bar() { + result = "OK" + } +} + +fun builder(block: suspend () -> Unit) { + block.startCoroutine(EmptyContinuation) +} + +fun box(): String { + builder { O.foo() } + return O.result +} diff --git a/compiler/testData/codegen/box/jvm8/defaults/suspendFunction.kt b/compiler/testData/codegen/box/jvm8/defaults/suspendFunction.kt new file mode 100644 index 00000000000..11672cb0c5b --- /dev/null +++ b/compiler/testData/codegen/box/jvm8/defaults/suspendFunction.kt @@ -0,0 +1,38 @@ +// !JVM_DEFAULT_MODE: enable +// TARGET_BACKEND: JVM +// JVM_TARGET: 1.8 +// WITH_COROUTINES +// WITH_RUNTIME + +import kotlin.coroutines.* +import helpers.* + +interface S { + suspend fun foo() +} + +interface T : S { + @JvmDefault + override suspend fun foo() { + bar() + } + + fun bar() +} + +object O : T { + var result = "" + + override fun bar() { + result = "OK" + } +} + +fun builder(block: suspend () -> Unit) { + block.startCoroutine(EmptyContinuation) +} + +fun box(): String { + builder { O.foo() } + return O.result +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index c3184839b99..94c4b17b4db 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -20793,6 +20793,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/jvm8/defaults/superCall.kt"); } + @Test + @TestMetadata("suspendFunction.kt") + public void testSuspendFunction() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/suspendFunction.kt"); + } + @Nested @TestMetadata("compiler/testData/codegen/box/jvm8/defaults/allCompatibility") @TestDataPath("$PROJECT_ROOT") @@ -20970,6 +20976,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/simpleFunction.kt"); } + @Test + @TestMetadata("suspendFunction.kt") + public void testSuspendFunction() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/suspendFunction.kt"); + } + @Nested @TestMetadata("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/delegationBy") @TestDataPath("$PROJECT_ROOT") @@ -21292,6 +21304,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/simpleFunction.kt"); } + @Test + @TestMetadata("suspendFunction.kt") + public void testSuspendFunction() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/suspendFunction.kt"); + } + @Nested @TestMetadata("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/delegationBy") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 12ccfcad951..62d8fef5831 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -20793,6 +20793,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/jvm8/defaults/superCall.kt"); } + @Test + @TestMetadata("suspendFunction.kt") + public void testSuspendFunction() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/suspendFunction.kt"); + } + @Nested @TestMetadata("compiler/testData/codegen/box/jvm8/defaults/allCompatibility") @TestDataPath("$PROJECT_ROOT") @@ -20970,6 +20976,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/simpleFunction.kt"); } + @Test + @TestMetadata("suspendFunction.kt") + public void testSuspendFunction() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/suspendFunction.kt"); + } + @Nested @TestMetadata("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/delegationBy") @TestDataPath("$PROJECT_ROOT") @@ -21292,6 +21304,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/simpleFunction.kt"); } + @Test + @TestMetadata("suspendFunction.kt") + public void testSuspendFunction() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/suspendFunction.kt"); + } + @Nested @TestMetadata("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/delegationBy") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index a9172726b39..497a9426735 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -17479,6 +17479,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/jvm8/defaults/superCall.kt"); } + @TestMetadata("suspendFunction.kt") + public void testSuspendFunction() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/suspendFunction.kt"); + } + @TestMetadata("compiler/testData/codegen/box/jvm8/defaults/allCompatibility") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) @@ -17631,6 +17636,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/simpleFunction.kt"); } + @TestMetadata("suspendFunction.kt") + public void testSuspendFunction() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/suspendFunction.kt"); + } + @TestMetadata("compiler/testData/codegen/box/jvm8/defaults/allCompatibility/delegationBy") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) @@ -17918,6 +17928,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/simpleFunction.kt"); } + @TestMetadata("suspendFunction.kt") + public void testSuspendFunction() throws Exception { + runTest("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/suspendFunction.kt"); + } + @TestMetadata("compiler/testData/codegen/box/jvm8/defaults/noDefaultImpls/delegationBy") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)