From a121a4a6b244122ec0116e64ee8a7a28058ca8bd Mon Sep 17 00:00:00 2001 From: Roman Artemev Date: Fri, 16 Mar 2018 20:43:41 +0300 Subject: [PATCH] Added test to check default params in declaration (issue KT-23239) --- .../inheritedFromExpectedMethod.kt | 30 ++++++++++++++++ .../inheritedInExpectedDeclarations.kt | 34 +++++++++++++++++++ .../multiplatform/defaultArguments/kt23239.kt | 34 +++++++++++++++++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 18 ++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 18 ++++++++++ .../LightAnalysisModeTestGenerated.java | 18 ++++++++++ .../semantics/JsCodegenBoxTestGenerated.java | 18 ++++++++++ 7 files changed, 170 insertions(+) create mode 100644 compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedFromExpectedMethod.kt create mode 100644 compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedInExpectedDeclarations.kt create mode 100644 compiler/testData/codegen/box/multiplatform/defaultArguments/kt23239.kt diff --git a/compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedFromExpectedMethod.kt b/compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedFromExpectedMethod.kt new file mode 100644 index 00000000000..c4ea69ccf78 --- /dev/null +++ b/compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedFromExpectedMethod.kt @@ -0,0 +1,30 @@ +// !LANGUAGE: +MultiPlatformProjects +// WITH_RUNTIME +// IGNORE_BACKEND: JVM_IR +// FILE: common.kt + +expect open class C() { + open fun f(p: Int = 2) : String +} + +// FILE: platform.kt + +import kotlin.test.assertEquals + +actual open class C { + actual open fun f(p: Int) = "C" + p +} + +open class D : C() { + override open fun f(p: Int) = "D" + p +} + +fun box(): String { + + assertEquals("C2", C().f()) + assertEquals("C9", C().f(9)) + assertEquals("D2", D().f()) + assertEquals("D5", D().f(5)) + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedInExpectedDeclarations.kt b/compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedInExpectedDeclarations.kt new file mode 100644 index 00000000000..abe6f5ca198 --- /dev/null +++ b/compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedInExpectedDeclarations.kt @@ -0,0 +1,34 @@ +// !LANGUAGE: +MultiPlatformProjects +// WITH_RUNTIME +// IGNORE_BACKEND: JVM_IR +// FILE: common.kt + +expect open class A() { + open fun f(p: Int = 1) : String +} + +expect open class B : A { + override open fun f(p: Int) : String +} + +// FILE: platform.kt + +import kotlin.test.assertEquals + +actual open class A { + actual open fun f(p: Int) = "A" + p +} + +actual open class B : A() { + actual override open fun f(p: Int) = "B" + p +} + +fun box(): String { + + assertEquals("A1", A().f()) + assertEquals("A9", A().f(9)) + assertEquals("B1", B().f()) + assertEquals("B5", B().f(5)) + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/multiplatform/defaultArguments/kt23239.kt b/compiler/testData/codegen/box/multiplatform/defaultArguments/kt23239.kt new file mode 100644 index 00000000000..55334ec1fda --- /dev/null +++ b/compiler/testData/codegen/box/multiplatform/defaultArguments/kt23239.kt @@ -0,0 +1,34 @@ +// !LANGUAGE: +MultiPlatformProjects +// WITH_RUNTIME +// IGNORE_BACKEND: JVM_IR +// FILE: common.kt + +expect open class C() { + open fun f(p: Int = 1) : String + open fun f2(p1: Int = 1, p2: Int = 2) : String + open fun ff(p1: Int, p2: Int = 2) : String + open fun fff(p1: Int, p2: Int, p3: Int = 3) : String + open fun fffx(p1: Int, p2: Int = 4, p3: Int = 5) : String +} +// FILE: platform.kt + +import kotlin.test.assertEquals + +actual open class C { + actual open fun f(p: Int) = "f" + p + actual open fun f2(p1: Int, p2: Int) = "f2" + p1 + "" + p2 + actual open fun ff(p1: Int, p2: Int) = "ff" + p1 + "" + p2 + actual open fun fff(p1: Int, p2: Int, p3: Int) = "fff" + p1 + "" + p2 + "" + p3 + actual open fun fffx(p1: Int, p2: Int, p3: Int) = "fffx" + p1 + "" + p2 + "" + p3 +} + +fun box(): String { + + assertEquals("f1", C().f()) + assertEquals("f212", C().f2()) + assertEquals("ff12", C().ff(1)) + assertEquals("fff123", C().fff(1, 2)) + assertEquals("fffx345", C().fffx(3)) + + 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 2ccbbcf6214..322237e821b 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 @@ -13168,11 +13168,29 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("inheritedFromExpectedMethod.kt") + public void testInheritedFromExpectedMethod() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedFromExpectedMethod.kt"); + doTest(fileName); + } + + @TestMetadata("inheritedInExpectedDeclarations.kt") + public void testInheritedInExpectedDeclarations() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedInExpectedDeclarations.kt"); + doTest(fileName); + } + @TestMetadata("inlineFunctionWithDefaultLambda.kt") public void testInlineFunctionWithDefaultLambda() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/multiplatform/defaultArguments/inlineFunctionWithDefaultLambda.kt"); doTest(fileName); } + + @TestMetadata("kt23239.kt") + public void testKt23239() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23239.kt"); + doTest(fileName); + } } } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index baf9a441272..459169b67d2 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -13168,11 +13168,29 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("inheritedFromExpectedMethod.kt") + public void testInheritedFromExpectedMethod() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedFromExpectedMethod.kt"); + doTest(fileName); + } + + @TestMetadata("inheritedInExpectedDeclarations.kt") + public void testInheritedInExpectedDeclarations() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedInExpectedDeclarations.kt"); + doTest(fileName); + } + @TestMetadata("inlineFunctionWithDefaultLambda.kt") public void testInlineFunctionWithDefaultLambda() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/multiplatform/defaultArguments/inlineFunctionWithDefaultLambda.kt"); doTest(fileName); } + + @TestMetadata("kt23239.kt") + public void testKt23239() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23239.kt"); + doTest(fileName); + } } } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index e4f1a578ede..01c992c6057 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -13168,11 +13168,29 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes doTest(fileName); } + @TestMetadata("inheritedFromExpectedMethod.kt") + public void testInheritedFromExpectedMethod() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedFromExpectedMethod.kt"); + doTest(fileName); + } + + @TestMetadata("inheritedInExpectedDeclarations.kt") + public void testInheritedInExpectedDeclarations() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedInExpectedDeclarations.kt"); + doTest(fileName); + } + @TestMetadata("inlineFunctionWithDefaultLambda.kt") public void testInlineFunctionWithDefaultLambda() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/multiplatform/defaultArguments/inlineFunctionWithDefaultLambda.kt"); doTest(fileName); } + + @TestMetadata("kt23239.kt") + public void testKt23239() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23239.kt"); + doTest(fileName); + } } } 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 5ff1f3cb8e8..56526f48684 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 @@ -15658,11 +15658,29 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { doTest(fileName); } + @TestMetadata("inheritedFromExpectedMethod.kt") + public void testInheritedFromExpectedMethod() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedFromExpectedMethod.kt"); + doTest(fileName); + } + + @TestMetadata("inheritedInExpectedDeclarations.kt") + public void testInheritedInExpectedDeclarations() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/multiplatform/defaultArguments/inheritedInExpectedDeclarations.kt"); + doTest(fileName); + } + @TestMetadata("inlineFunctionWithDefaultLambda.kt") public void testInlineFunctionWithDefaultLambda() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/multiplatform/defaultArguments/inlineFunctionWithDefaultLambda.kt"); doTest(fileName); } + + @TestMetadata("kt23239.kt") + public void testKt23239() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/multiplatform/defaultArguments/kt23239.kt"); + doTest(fileName); + } } }