JS: fix object expression constructor delegation to secondary constructors with default arguments (KT-30517 fixed)

This commit is contained in:
Anton Bannykh
2019-12-13 14:31:50 +03:00
committed by Anton Bannykh
parent 419d414681
commit 9a971172c9
9 changed files with 122 additions and 9 deletions
@@ -6954,10 +6954,20 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/defaultArguments/constructor/kt2852.kt");
}
@TestMetadata("kt30517.kt")
public void testKt30517() throws Exception {
runTest("compiler/testData/codegen/box/defaultArguments/constructor/kt30517.kt");
}
@TestMetadata("kt3060.kt")
public void testKt3060() throws Exception {
runTest("compiler/testData/codegen/box/defaultArguments/constructor/kt3060.kt");
}
@TestMetadata("objectExpressionDelegatingToSecondaryConstructor.kt")
public void testObjectExpressionDelegatingToSecondaryConstructor() throws Exception {
runTest("compiler/testData/codegen/box/defaultArguments/constructor/objectExpressionDelegatingToSecondaryConstructor.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/defaultArguments/convention")
@@ -8029,10 +8029,20 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/defaultArguments/constructor/kt2852.kt");
}
@TestMetadata("kt30517.kt")
public void testKt30517() throws Exception {
runTest("compiler/testData/codegen/box/defaultArguments/constructor/kt30517.kt");
}
@TestMetadata("kt3060.kt")
public void testKt3060() throws Exception {
runTest("compiler/testData/codegen/box/defaultArguments/constructor/kt3060.kt");
}
@TestMetadata("objectExpressionDelegatingToSecondaryConstructor.kt")
public void testObjectExpressionDelegatingToSecondaryConstructor() throws Exception {
runTest("compiler/testData/codegen/box/defaultArguments/constructor/objectExpressionDelegatingToSecondaryConstructor.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/defaultArguments/convention")
@@ -242,16 +242,20 @@ public final class ClassInitializerTranslator extends AbstractTranslator {
addCallToSuperMethod(arguments, initializer, superCall.getCall().getCallElement());
}
else {
int maxValueArgumentIndex = 0;
for (ValueParameterDescriptor arg : superCall.getValueArguments().keySet()) {
ResolvedValueArgument resolvedArg = superCall.getValueArguments().get(arg);
if (!(resolvedArg instanceof DefaultValueArgument)) {
maxValueArgumentIndex = Math.max(maxValueArgumentIndex, arg.getIndex() + 1);
// Add `void 0` for the trailing default arguments
// Anonymous object constructor already has all the parameters proxied, including ones with default values
if (!DescriptorUtils.isAnonymousObject(classDescriptor)) {
int maxValueArgumentIndex = 0;
for (ValueParameterDescriptor arg : superCall.getValueArguments().keySet()) {
ResolvedValueArgument resolvedArg = superCall.getValueArguments().get(arg);
if (!(resolvedArg instanceof DefaultValueArgument)) {
maxValueArgumentIndex = Math.max(maxValueArgumentIndex, arg.getIndex() + 1);
}
}
int padSize = superDescriptor.getValueParameters().size() - maxValueArgumentIndex;
while (padSize-- > 0) {
arguments.add(Namer.getUndefinedExpression());
}
}
int padSize = superDescriptor.getValueParameters().size() - maxValueArgumentIndex;
while (padSize-- > 0) {
arguments.add(Namer.getUndefinedExpression());
}
addCallToSuperSecondaryConstructor(arguments, superDescriptor);
}