JVM IR: Fix types in generated function reference constructor

For references to suspend functions this fixes an IllegalStateException
in the type mapper, which is what the "suspendFunctionMethodReference"
test is about.
This commit is contained in:
Steven Schäfer
2020-09-24 16:49:19 +02:00
committed by Alexander Udalov
parent f3db113a82
commit 20a5c44e41
9 changed files with 48 additions and 6 deletions
@@ -6903,6 +6903,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendFunImportedFromObject.kt", "kotlin.coroutines");
}
@TestMetadata("suspendFunctionMethodReference.kt")
public void testSuspendFunctionMethodReference() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendFunctionMethodReference.kt");
}
@TestMetadata("suspendImplBridge.kt")
public void testSuspendImplBridge() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendImplBridge.kt");
@@ -273,12 +273,8 @@ internal class FunctionReferenceLowering(private val context: JvmBackendContext)
}.apply {
// Add receiver parameter for bound function references
if (samSuperType == null) {
boundReceiver?.first?.let { param ->
valueParameters += param.copyTo(
irFunction = this,
index = 0,
type = param.type.substitute(typeArgumentsMap)
)
boundReceiver?.let { (param, arg) ->
valueParameters += param.copyTo(irFunction = this, index = 0, type = arg.type)
}
}
@@ -0,0 +1,11 @@
// IGNORE_BACKEND: JVM
// IGNORE_BACKEND_FIR: JVM_IR
fun f(a: suspend () -> Unit): String {
val f = a::invoke
return "OK"
}
fun box(): String {
return f {}
}
@@ -7303,6 +7303,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendFunImportedFromObject.kt", "kotlin.coroutines");
}
@TestMetadata("suspendFunctionMethodReference.kt")
public void testSuspendFunctionMethodReference() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendFunctionMethodReference.kt");
}
@TestMetadata("suspendImplBridge.kt")
public void testSuspendImplBridge() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendImplBridge.kt");
@@ -6466,6 +6466,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Coroutines extends AbstractLightAnalysisModeTest {
@TestMetadata("suspendFunctionMethodReference.kt")
public void ignoreSuspendFunctionMethodReference() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendFunctionMethodReference.kt");
}
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
}
@@ -6903,6 +6903,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendFunImportedFromObject.kt", "kotlin.coroutines");
}
@TestMetadata("suspendFunctionMethodReference.kt")
public void testSuspendFunctionMethodReference() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendFunctionMethodReference.kt");
}
@TestMetadata("suspendImplBridge.kt")
public void testSuspendImplBridge() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendImplBridge.kt");
@@ -5753,6 +5753,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendFunImportedFromObject.kt", "kotlin.coroutines");
}
@TestMetadata("suspendFunctionMethodReference.kt")
public void testSuspendFunctionMethodReference() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendFunctionMethodReference.kt");
}
@TestMetadata("suspendInCycle.kt")
public void testSuspendInCycle_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendInCycle.kt", "kotlin.coroutines");
@@ -5753,6 +5753,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendFunImportedFromObject.kt", "kotlin.coroutines");
}
@TestMetadata("suspendFunctionMethodReference.kt")
public void testSuspendFunctionMethodReference() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendFunctionMethodReference.kt");
}
@TestMetadata("suspendInCycle.kt")
public void testSuspendInCycle_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendInCycle.kt", "kotlin.coroutines");
@@ -5753,6 +5753,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendFunImportedFromObject.kt", "kotlin.coroutines");
}
@TestMetadata("suspendFunctionMethodReference.kt")
public void testSuspendFunctionMethodReference() throws Exception {
runTest("compiler/testData/codegen/box/coroutines/suspendFunctionMethodReference.kt");
}
@TestMetadata("suspendInCycle.kt")
public void testSuspendInCycle_1_3() throws Exception {
runTestWithPackageReplacement("compiler/testData/codegen/box/coroutines/suspendInCycle.kt", "kotlin.coroutines");