Fix callable reference adaptation for vararg in fake override

`mappedVarargElements` are populated with parameters from
`argumentMapping`, which is computed using `ArgumentsToParametersMapper`
which calls `original` on all value parameters (see
ArgumentsToParametersMapper.kt:136).

So the code that adds empty lists for unassigned vararg parameters
should also call `original`. Otherwise, in the added test, we ended up
with two arguments for the parameter `s` in `id(::base1)`, one for
`Base.s` containing the correct value, and another for `Derived.s`
containing the empty list. Psi2ir took the last one, which resulted in
empty array being passed to the vararg parameter.

Note that all of this is caused by the fact that `original` of a fake
override parameter is the parameter of the base function. This seems
suspicious because `original` of a fake override _function_ is that fake
override itself (NOT the base function), but this would probably be very
risky to change at this point.

 #KT-48835 Fixed
This commit is contained in:
Alexander Udalov
2021-09-30 01:31:50 +02:00
parent 9857af7823
commit dbd28142d0
10 changed files with 87 additions and 3 deletions
@@ -1816,6 +1816,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/unboundReferences.kt");
}
@TestMetadata("varargFromBaseClass.kt")
public void testVarargFromBaseClass() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/varargFromBaseClass.kt");
}
@TestMetadata("varargViewedAsArray.kt")
public void testVarargViewedAsArray() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/varargViewedAsArray.kt");
@@ -1816,6 +1816,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/unboundReferences.kt");
}
@TestMetadata("varargFromBaseClass.kt")
public void testVarargFromBaseClass() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/varargFromBaseClass.kt");
}
@TestMetadata("varargViewedAsArray.kt")
public void testVarargViewedAsArray() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/varargViewedAsArray.kt");
@@ -1781,6 +1781,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/unboundReferences.kt");
}
@TestMetadata("varargFromBaseClass.kt")
public void testVarargFromBaseClass() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/varargFromBaseClass.kt");
}
@TestMetadata("varargViewedAsArray.kt")
public void testVarargViewedAsArray() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/varargViewedAsArray.kt");
@@ -1616,6 +1616,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/unboundReferences.kt");
}
@TestMetadata("varargFromBaseClass.kt")
public void testVarargFromBaseClass() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/varargFromBaseClass.kt");
}
@TestMetadata("varargViewedAsArray.kt")
public void testVarargViewedAsArray() throws Exception {
runTest("compiler/testData/codegen/box/callableReference/adaptedReferences/varargViewedAsArray.kt");