diff --git a/compiler/testData/codegen/box/classes/delegateConstructorCallWithKeywords.kt b/compiler/testData/codegen/box/classes/delegateConstructorCallWithKeywords.kt new file mode 100644 index 00000000000..37d32d3d190 --- /dev/null +++ b/compiler/testData/codegen/box/classes/delegateConstructorCallWithKeywords.kt @@ -0,0 +1,30 @@ +open class A(val x: String) { + constructor(`in`: String, y: String) : this(`in` + y) + + constructor(`in`: Int = 23) : this(`in`.toString()) +} + +class B(`in`: String) : A(`in`) + +class C : A { + constructor(`in`: String) : super(`in`) +} + +fun box(): String { + val a1 = A("a", "b") + if (a1.x != "ab") return "fail1: ${a1.x}" + + val a2 = A(42) + if (a2.x != "42") return "fail2: ${a2.x}" + + val a3 = A() + if (a3.x != "23") return "fail3: ${a3.x}" + + val b = B("q") + if (b.x != "q") return "fail4: ${b.x}" + + val c = C("w") + if (c.x != "w") return "fail5: ${c.x}" + + return "OK" +} \ No newline at end of file diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index e7aa24af31f..6b92ad68983 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -2999,6 +2999,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("delegateConstructorCallWithKeywords.kt") + public void testDelegateConstructorCallWithKeywords() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/classes/delegateConstructorCallWithKeywords.kt"); + doTest(fileName); + } + @TestMetadata("delegation2.kt") public void testDelegation2() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/classes/delegation2.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index c39012c5712..6bc55870ce5 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -2999,6 +2999,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("delegateConstructorCallWithKeywords.kt") + public void testDelegateConstructorCallWithKeywords() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/classes/delegateConstructorCallWithKeywords.kt"); + doTest(fileName); + } + @TestMetadata("delegation2.kt") public void testDelegation2() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/classes/delegation2.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 4afc45bcab7..efdee6f4b8f 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -2999,6 +2999,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes doTest(fileName); } + @TestMetadata("delegateConstructorCallWithKeywords.kt") + public void testDelegateConstructorCallWithKeywords() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/classes/delegateConstructorCallWithKeywords.kt"); + doTest(fileName); + } + @TestMetadata("delegation2.kt") public void testDelegation2() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/classes/delegation2.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index b577fdd0260..4c1c382eed1 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -3581,6 +3581,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { doTest(fileName); } + @TestMetadata("delegateConstructorCallWithKeywords.kt") + public void testDelegateConstructorCallWithKeywords() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/classes/delegateConstructorCallWithKeywords.kt"); + doTest(fileName); + } + @TestMetadata("delegation2.kt") public void testDelegation2() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/classes/delegation2.kt"); diff --git a/js/js.translator/src/org/jetbrains/kotlin/js/translate/declaration/ClassTranslator.kt b/js/js.translator/src/org/jetbrains/kotlin/js/translate/declaration/ClassTranslator.kt index 7a065d1156f..00e2917e9b9 100644 --- a/js/js.translator/src/org/jetbrains/kotlin/js/translate/declaration/ClassTranslator.kt +++ b/js/js.translator/src/org/jetbrains/kotlin/js/translate/declaration/ClassTranslator.kt @@ -253,8 +253,8 @@ class ClassTranslator private constructor( context.addDeclarationStatement(constructorInitializer.makeStmt()) context = context.contextWithScope(constructorInitializer) - context.translateAndAliasParameters(constructorDescriptor, constructorInitializer.parameters) - .translateFunction(constructor, constructorInitializer) + .translateAndAliasParameters(constructorDescriptor, constructorInitializer.parameters) + context.translateFunction(constructor, constructorInitializer) // Translate super/this call val superCallGenerators = mutableListOf<(MutableList) -> Unit>()