JVM IR: Use INVOKESPECIAL instead of INVOKEVIRTUAL for default private

suspend functions.

 #KT-26592
This commit is contained in:
Ilmir Usmanov
2021-02-23 15:59:51 +01:00
parent 3ee62cb1b2
commit d44799fa78
6 changed files with 58 additions and 1 deletions
@@ -9549,6 +9549,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/interfaceMethodWithBodyGeneric.kt");
}
@Test
@TestMetadata("jvmDefault.kt")
public void testJvmDefault() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault.kt");
}
@Test
@TestMetadata("overrideInInlineClass.kt")
public void testOverrideInInlineClass() throws Exception {
@@ -403,7 +403,7 @@ class MethodSignatureMapper(private val context: JvmBackendContext) {
callee.dispatchReceiverParameter == null -> Opcodes.INVOKESTATIC
isSuperCall -> Opcodes.INVOKESPECIAL
isInterface && !DescriptorVisibilities.isPrivate(callee.visibility) -> Opcodes.INVOKEINTERFACE
DescriptorVisibilities.isPrivate(callee.visibility) && !callee.isSuspend -> Opcodes.INVOKESPECIAL
DescriptorVisibilities.isPrivate(callee.visibility) -> Opcodes.INVOKESPECIAL
else -> Opcodes.INVOKEVIRTUAL
}
@@ -0,0 +1,34 @@
// WITH_RUNTIME
// !JVM_DEFAULT_MODE: all
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// IGNORE_BACKEND: JVM
import kotlin.coroutines.*
interface Foo {
private suspend fun test(): String {
return "OK"
}
suspend fun foo(): String {
return test()
}
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(Continuation(EmptyCoroutineContext) {
it.getOrThrow()
})
}
fun box(): String {
var res = "FAIL"
builder {
val foo: Foo = object : Foo{}
res = foo.foo()
}
return res
}
@@ -9549,6 +9549,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/interfaceMethodWithBodyGeneric.kt");
}
@Test
@TestMetadata("jvmDefault.kt")
public void testJvmDefault() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault.kt");
}
@Test
@TestMetadata("overrideInInlineClass.kt")
public void testOverrideInInlineClass() throws Exception {
@@ -9549,6 +9549,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/interfaceMethodWithBodyGeneric.kt");
}
@Test
@TestMetadata("jvmDefault.kt")
public void testJvmDefault() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault.kt");
}
@Test
@TestMetadata("overrideInInlineClass.kt")
public void testOverrideInInlineClass() throws Exception {
@@ -7517,6 +7517,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/funInterface.kt");
}
@TestMetadata("jvmDefault.kt")
public void ignoreJvmDefault() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/featureIntersection/jvmDefault.kt");
}
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
}