Do not generate $suspendImpl for JvmDefault functions in interfaces
#KT-44533 Fixed
This commit is contained in:
+18
@@ -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")
|
||||
|
||||
+2
-1
@@ -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 }
|
||||
|
||||
+38
@@ -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
|
||||
}
|
||||
+37
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
+18
@@ -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")
|
||||
|
||||
+18
@@ -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")
|
||||
|
||||
+15
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user