JVM: Fix default parameter values handling

When we generate call for 'foo', we make decision about invoking
a 'foo$default' too late, after the call arguments are generated.
If 'foo' was an override, and base class (interface) was generic,
'foo' in base class could have a different Kotlin and JVM
signature, so the arguments we generated could be generated wrong
(primitive or inline class values instead of boxes, see KT-38680).
Also, we always selected first base class in supertypes list,
which caused KT-15971.

Look into resolved call and see if we should actually call
'foo$default' instead of 'foo' when determining actual callable.

Overrides can't introduce default parameter values, and
override-equivalent inherited methods with default parameters
is an error in a child class. Thus, if we are calling a class
member function with a default parameters, there should be one
and only one overridden function that has default parameter values
and overrides nothing.
This commit is contained in:
Dmitry Petrov
2020-05-12 18:42:27 +03:00
parent dc9f64fc9d
commit 2f82c5b6af
21 changed files with 188 additions and 62 deletions
@@ -9868,21 +9868,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class DefaultArguments extends AbstractLightAnalysisModeTest {
@TestMetadata("implementedByFake.kt")
public void ignoreImplementedByFake() throws Exception {
runTest("compiler/testData/codegen/box/defaultArguments/implementedByFake.kt");
}
@TestMetadata("implementedByFake2.kt")
public void ignoreImplementedByFake2() throws Exception {
runTest("compiler/testData/codegen/box/defaultArguments/implementedByFake2.kt");
}
@TestMetadata("implementedByFake3.kt")
public void ignoreImplementedByFake3() throws Exception {
runTest("compiler/testData/codegen/box/defaultArguments/implementedByFake3.kt");
}
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
}
@@ -9901,6 +9886,21 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/defaultArguments/complexInheritance.kt");
}
@TestMetadata("implementedByFake.kt")
public void testImplementedByFake() throws Exception {
runTest("compiler/testData/codegen/box/defaultArguments/implementedByFake.kt");
}
@TestMetadata("implementedByFake2.kt")
public void testImplementedByFake2() throws Exception {
runTest("compiler/testData/codegen/box/defaultArguments/implementedByFake2.kt");
}
@TestMetadata("implementedByFake3.kt")
public void testImplementedByFake3() throws Exception {
runTest("compiler/testData/codegen/box/defaultArguments/implementedByFake3.kt");
}
@TestMetadata("inheritedFromInterfaceViaAbstractSuperclass.kt")
public void testInheritedFromInterfaceViaAbstractSuperclass() throws Exception {
runTest("compiler/testData/codegen/box/defaultArguments/inheritedFromInterfaceViaAbstractSuperclass.kt");
@@ -10106,26 +10106,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Function extends AbstractLightAnalysisModeTest {
@TestMetadata("funInTraitChain.kt")
public void ignoreFunInTraitChain() throws Exception {
runTest("compiler/testData/codegen/box/defaultArguments/function/funInTraitChain.kt");
}
@TestMetadata("kt15971.kt")
public void ignoreKt15971() throws Exception {
runTest("compiler/testData/codegen/box/defaultArguments/function/kt15971.kt");
}
@TestMetadata("kt15971_2.kt")
public void ignoreKt15971_2() throws Exception {
runTest("compiler/testData/codegen/box/defaultArguments/function/kt15971_2.kt");
}
@TestMetadata("kt15971_3.kt")
public void ignoreKt15971_3() throws Exception {
runTest("compiler/testData/codegen/box/defaultArguments/function/kt15971_3.kt");
}
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
}
@@ -10194,6 +10174,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/defaultArguments/function/funInTrait.kt");
}
@TestMetadata("funInTraitChain.kt")
public void testFunInTraitChain() throws Exception {
runTest("compiler/testData/codegen/box/defaultArguments/function/funInTraitChain.kt");
}
@TestMetadata("innerExtentionFunction.kt")
public void testInnerExtentionFunction() throws Exception {
runTest("compiler/testData/codegen/box/defaultArguments/function/innerExtentionFunction.kt");
@@ -10214,6 +10199,21 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/defaultArguments/function/innerExtentionFunctionManyArgs.kt");
}
@TestMetadata("kt15971.kt")
public void testKt15971() throws Exception {
runTest("compiler/testData/codegen/box/defaultArguments/function/kt15971.kt");
}
@TestMetadata("kt15971_2.kt")
public void testKt15971_2() throws Exception {
runTest("compiler/testData/codegen/box/defaultArguments/function/kt15971_2.kt");
}
@TestMetadata("kt15971_3.kt")
public void testKt15971_3() throws Exception {
runTest("compiler/testData/codegen/box/defaultArguments/function/kt15971_3.kt");
}
@TestMetadata("kt36188.kt")
public void testKt36188() throws Exception {
runTest("compiler/testData/codegen/box/defaultArguments/function/kt36188.kt");
@@ -10798,11 +10798,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Delegation extends AbstractLightAnalysisModeTest {
@TestMetadata("withDefaultParameters.kt")
public void ignoreWithDefaultParameters() throws Exception {
runTest("compiler/testData/codegen/box/delegation/withDefaultParameters.kt");
}
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
}
@@ -10880,6 +10875,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
public void testSimple1_0() throws Exception {
runTest("compiler/testData/codegen/box/delegation/simple1.0.kt");
}
@TestMetadata("withDefaultParameters.kt")
public void testWithDefaultParameters() throws Exception {
runTest("compiler/testData/codegen/box/delegation/withDefaultParameters.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/destructuringDeclInLambdaParam")
@@ -14133,6 +14133,16 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/inlineClasses/kt38680.kt");
}
@TestMetadata("kt38680a.kt")
public void testKt38680a() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt38680a.kt");
}
@TestMetadata("kt38680b.kt")
public void testKt38680b() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/kt38680b.kt");
}
@TestMetadata("mangledDefaultParameterFunction.kt")
public void testMangledDefaultParameterFunction() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/mangledDefaultParameterFunction.kt");
@@ -18634,11 +18644,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class DefaultArguments extends AbstractLightAnalysisModeTest {
@TestMetadata("delegatedExpectedInterface.kt")
public void ignoreDelegatedExpectedInterface() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/delegatedExpectedInterface.kt");
}
@TestMetadata("superCall.kt")
public void ignoreSuperCall() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/superCall.kt");
@@ -18672,6 +18677,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/constructor.kt");
}
@TestMetadata("delegatedExpectedInterface.kt")
public void testDelegatedExpectedInterface() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/delegatedExpectedInterface.kt");
}
@TestMetadata("dispatchReceiverValue.kt")
public void testDispatchReceiverValue() throws Exception {
runTest("compiler/testData/codegen/box/multiplatform/defaultArguments/dispatchReceiverValue.kt");