JVM_IR KT-44483 argument adaptation is already done in PSI2IR

This commit is contained in:
Dmitry Petrov
2021-02-10 12:55:28 +03:00
parent f1b0e893ae
commit b1ab64e854
10 changed files with 48 additions and 20 deletions
@@ -2440,6 +2440,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/callableReference/kt37604.kt");
}
@Test
@TestMetadata("kt44483.kt")
public void testKt44483() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/kt44483.kt");
}
@Test
@TestMetadata("nested.kt")
public void testNested() throws Exception {
@@ -574,25 +574,6 @@ internal class FunctionReferenceLowering(private val context: JvmBackendContext)
else
irGet(receiver!!)
// If a vararg parameter corresponds to exactly one KFunction argument, which is an array, that array
// is forwarded as is.
//
// fun f(x: (Int, Array<String>) -> String) = x(0, arrayOf("OK", "FAIL"))
// fun h(i: Int, vararg xs: String) = xs[i]
// f(::h)
//
parameter.isVararg && unboundIndex < argumentTypes.size && parameter.type == valueParameters[unboundIndex].type ->
irGet(valueParameters[unboundIndex++])
// In all other cases, excess arguments are packed into a new array.
//
// fun g(x: (Int, String, String) -> String) = x(0, "OK", "FAIL")
// f(::h) == g(::h)
//
parameter.isVararg && (unboundIndex < argumentTypes.size || !parameter.hasDefaultValue()) ->
irArray(parameter.type) {
(unboundIndex until argumentTypes.size).forEach { +irGet(valueParameters[unboundIndex++]) }
}
unboundIndex >= argumentTypes.size ->
// Default value argument (this pass doesn't handle suspend functions, otherwise
// it could also be the continuation argument)
@@ -1,4 +1,3 @@
fun useUnit(fn: () -> Unit) {
fn.invoke()
}
@@ -0,0 +1,10 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WITH_RUNTIME
fun <K, V> f(vararg p: Pair<K, V>): K = p[0].first
fun box(): String {
// NB this is not an adapted function reference
val f: (Array<out Pair<String, Int>>) -> String = ::f
return f(arrayOf("OK" to 0))
}
@@ -2440,6 +2440,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/callableReference/kt37604.kt");
}
@Test
@TestMetadata("kt44483.kt")
public void testKt44483() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/kt44483.kt");
}
@Test
@TestMetadata("nested.kt")
public void testNested() throws Exception {
@@ -2440,6 +2440,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/callableReference/kt37604.kt");
}
@Test
@TestMetadata("kt44483.kt")
public void testKt44483() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/kt44483.kt");
}
@Test
@TestMetadata("nested.kt")
public void testNested() throws Exception {
@@ -2145,6 +2145,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/callableReference/kt37604.kt");
}
@TestMetadata("kt44483.kt")
public void testKt44483() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/kt44483.kt");
}
@TestMetadata("nested.kt")
public void testNested() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/nested.kt");
@@ -1460,6 +1460,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
runTest("compiler/testData/codegen/box/callableReference/kt37604.kt");
}
@TestMetadata("kt44483.kt")
public void testKt44483() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/kt44483.kt");
}
@TestMetadata("nested.kt")
public void testNested() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/nested.kt");
@@ -1460,6 +1460,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/callableReference/kt37604.kt");
}
@TestMetadata("kt44483.kt")
public void testKt44483() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/kt44483.kt");
}
@TestMetadata("nested.kt")
public void testNested() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/nested.kt");
@@ -1460,6 +1460,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/callableReference/kt37604.kt");
}
@TestMetadata("kt44483.kt")
public void testKt44483() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/kt44483.kt");
}
@TestMetadata("nested.kt")
public void testNested() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/nested.kt");