Fix JvmOverloads generation for actual methods
`countDefaultParameters` uses `hasDefaultValue` to compute the number of parameters which have default values, which handles actual parameters (who have default values in the expected declaration) correctly. Thus, `getRemainingParameters` should use it as well to determine the list of parameters to be skipped in each generated overload #KT-23910 Fixed
This commit is contained in:
+1
-1
@@ -240,7 +240,7 @@ class DefaultParameterValueSubstitutor(val state: GenerationState) {
|
|||||||
|
|
||||||
private fun getRemainingParameters(functionDescriptor: FunctionDescriptor, substituteCount: Int): List<ValueParameterDescriptor> {
|
private fun getRemainingParameters(functionDescriptor: FunctionDescriptor, substituteCount: Int): List<ValueParameterDescriptor> {
|
||||||
var remainingCount = functionDescriptor.countDefaultParameters() - substituteCount
|
var remainingCount = functionDescriptor.countDefaultParameters() - substituteCount
|
||||||
return functionDescriptor.valueParameters.filter { !it.declaresDefaultValue() || --remainingCount >= 0 }
|
return functionDescriptor.valueParameters.filter { !it.hasDefaultValue() || --remainingCount >= 0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun isEmptyConstructorNeeded(constructorDescriptor: ConstructorDescriptor, classOrObject: KtPureClassOrObject): Boolean {
|
private fun isEmptyConstructorNeeded(constructorDescriptor: ConstructorDescriptor, classOrObject: KtPureClassOrObject): Boolean {
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
// !LANGUAGE: +MultiPlatformProjects
|
||||||
|
// TARGET_BACKEND: JVM
|
||||||
|
// WITH_RUNTIME
|
||||||
|
// FILE: J.java
|
||||||
|
|
||||||
|
public class J {
|
||||||
|
public static String test() {
|
||||||
|
JvmKt.foo(-1);
|
||||||
|
JvmKt.foo(5, 5);
|
||||||
|
return "OK";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: common.kt
|
||||||
|
|
||||||
|
expect fun foo(j: Int, i: Int = -1)
|
||||||
|
|
||||||
|
// FILE: jvm.kt
|
||||||
|
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
|
@JvmOverloads
|
||||||
|
actual fun foo(j: Int, i: Int) {
|
||||||
|
assertEquals(j, i)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
foo(-1)
|
||||||
|
foo(5, 5)
|
||||||
|
return J.test();
|
||||||
|
}
|
||||||
Generated
+5
@@ -13288,6 +13288,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/inlineFunctionWithDefaultLambda.kt");
|
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/inlineFunctionWithDefaultLambda.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("jvmOverloads.kt")
|
||||||
|
public void testJvmOverloads() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/jvmOverloads.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt23239.kt")
|
@TestMetadata("kt23239.kt")
|
||||||
public void testKt23239() throws Exception {
|
public void testKt23239() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23239.kt");
|
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23239.kt");
|
||||||
|
|||||||
+5
@@ -13288,6 +13288,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/inlineFunctionWithDefaultLambda.kt");
|
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/inlineFunctionWithDefaultLambda.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("jvmOverloads.kt")
|
||||||
|
public void testJvmOverloads() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/jvmOverloads.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt23239.kt")
|
@TestMetadata("kt23239.kt")
|
||||||
public void testKt23239() throws Exception {
|
public void testKt23239() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23239.kt");
|
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23239.kt");
|
||||||
|
|||||||
+5
@@ -13288,6 +13288,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/inlineFunctionWithDefaultLambda.kt");
|
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/inlineFunctionWithDefaultLambda.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("jvmOverloads.kt")
|
||||||
|
public void testJvmOverloads() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/jvmOverloads.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt23239.kt")
|
@TestMetadata("kt23239.kt")
|
||||||
public void testKt23239() throws Exception {
|
public void testKt23239() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23239.kt");
|
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23239.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user