JVM_IR: use substituted return type in function reference invoke

#KT-46982 Fixed
This commit is contained in:
pyos
2021-05-31 10:46:12 +02:00
committed by Dmitry Petrov
parent 84c10079e4
commit 5c2753b5d1
10 changed files with 52 additions and 2 deletions
@@ -2446,6 +2446,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("arrayConstructor.kt")
public void testArrayConstructor() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/arrayConstructor.kt");
}
@Test
@TestMetadata("arrayConstructorArgument.kt")
public void testArrayConstructorArgument() throws Exception {
@@ -383,6 +383,7 @@ internal class FunctionReferenceLowering(private val context: JvmBackendContext)
// The type of the reference is KFunction<in A1, ..., in An, out R>
private val parameterTypes = (irFunctionReference.type as IrSimpleType).arguments.map { (it as IrTypeProjection).type }
private val argumentTypes = parameterTypes.dropLast(1)
private val referenceReturnType = parameterTypes.last()
private val typeArgumentsMap = irFunctionReference.typeSubstitutionMap
@@ -671,7 +672,7 @@ internal class FunctionReferenceLowering(private val context: JvmBackendContext)
functionReferenceClass.addFunction {
setSourceRange(if (isLambda) callee else irFunctionReference)
name = superMethod.name
returnType = callee.returnType
returnType = referenceReturnType
isSuspend = callee.isSuspend
}.apply {
overriddenSymbols += superMethod.symbol
@@ -703,7 +704,7 @@ internal class FunctionReferenceLowering(private val context: JvmBackendContext)
body = context.createJvmIrBuilder(symbol, startOffset, endOffset).run {
var unboundIndex = 0
val call = irCall(callee).apply {
val call = irCall(callee.symbol, referenceReturnType).apply {
for (typeParameter in irFunctionReference.symbol.owner.allTypeParameters) {
putTypeArgument(typeParameter.index, typeArgumentsMap[typeParameter.symbol])
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
// IGNORE_BACKEND: JS_IR
fun g(b: (Int, (Int) -> String) -> Array<String>): Array<String> =
b(1) { "OK" }
fun box(): String = g(::Array)[0]
@@ -2446,6 +2446,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@Test
@TestMetadata("arrayConstructor.kt")
public void testArrayConstructor() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/arrayConstructor.kt");
}
@Test
@TestMetadata("arrayConstructorArgument.kt")
public void testArrayConstructorArgument() throws Exception {
@@ -2446,6 +2446,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@Test
@TestMetadata("arrayConstructor.kt")
public void testArrayConstructor() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/arrayConstructor.kt");
}
@Test
@TestMetadata("arrayConstructorArgument.kt")
public void testArrayConstructorArgument() throws Exception {
@@ -2170,6 +2170,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@TestMetadata("arrayConstructor.kt")
public void testArrayConstructor() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/arrayConstructor.kt");
}
@TestMetadata("arrayConstructorArgument.kt")
public void testArrayConstructorArgument() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/arrayConstructorArgument.kt");
@@ -1460,6 +1460,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
}
@TestMetadata("arrayConstructor.kt")
public void testArrayConstructor() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/arrayConstructor.kt");
}
@TestMetadata("arrayConstructorArgument.kt")
public void testArrayConstructorArgument() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/arrayConstructorArgument.kt");
@@ -1460,6 +1460,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
}
@TestMetadata("arrayConstructor.kt")
public void testArrayConstructor() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/arrayConstructor.kt");
}
@TestMetadata("arrayConstructorArgument.kt")
public void testArrayConstructorArgument() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/arrayConstructorArgument.kt");
@@ -1460,6 +1460,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true);
}
@TestMetadata("arrayConstructor.kt")
public void testArrayConstructor() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/arrayConstructor.kt");
}
@TestMetadata("arrayConstructorArgument.kt")
public void testArrayConstructorArgument() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/arrayConstructorArgument.kt");
@@ -1270,6 +1270,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true);
}
@TestMetadata("arrayConstructor.kt")
public void testArrayConstructor() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/arrayConstructor.kt");
}
@TestMetadata("arrayOf.kt")
public void testArrayOf() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/arrayOf.kt");