From a2897a29b514ddf72368476a791dd5e53782fdfe Mon Sep 17 00:00:00 2001 From: Igor Chevdar Date: Thu, 15 Feb 2018 18:26:45 +0300 Subject: [PATCH] Added tests on default arguments of fake overridden functions --- .../defaultArguments/implementedByFake2.kt | 42 ++++++++++++++++ .../defaultArguments/implementedByFake3.kt | 48 +++++++++++++++++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 24 ++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 24 ++++++++++ .../LightAnalysisModeTestGenerated.java | 24 ++++++++++ .../semantics/JsCodegenBoxTestGenerated.java | 24 ++++++++++ 6 files changed, 186 insertions(+) create mode 100644 compiler/testData/codegen/box/defaultArguments/implementedByFake2.kt create mode 100644 compiler/testData/codegen/box/defaultArguments/implementedByFake3.kt diff --git a/compiler/testData/codegen/box/defaultArguments/implementedByFake2.kt b/compiler/testData/codegen/box/defaultArguments/implementedByFake2.kt new file mode 100644 index 00000000000..e4f4625658f --- /dev/null +++ b/compiler/testData/codegen/box/defaultArguments/implementedByFake2.kt @@ -0,0 +1,42 @@ +// IGNORE_BACKEND: JVM, JS + +interface I { + val prop: T + + fun f(x: String = "1"): String + + fun g(x: String = "2"): String + + fun h(x: T = prop): T +} + +interface I2 : I + +open class A { + open fun f(x: String) = x + + open fun g(x: T) = x + + open fun h(x: String) = x +} + +class B : A(), I2 { + override val prop + get() = "3" +} + +fun box(): String { + val i: I = B() + var result = i.f() + i.g() + i.h() + if (result != "123") return "fail1: $result" + + val b = B() + result = b.f() + b.g() + b.h() + if (result != "123") return "fail2: $result" + + val a: A = B() + result = a.f("q") + a.g("w") + a.h("e") + if (result != "qwe") return "fail3: $result" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/defaultArguments/implementedByFake3.kt b/compiler/testData/codegen/box/defaultArguments/implementedByFake3.kt new file mode 100644 index 00000000000..1d3a4ee8cbf --- /dev/null +++ b/compiler/testData/codegen/box/defaultArguments/implementedByFake3.kt @@ -0,0 +1,48 @@ +// IGNORE_BACKEND: JVM, JS + +interface I { + val prop: T + + fun f(x: String = "1"): String + + fun g(x: String = "2"): String + + fun h(x: T = prop): T +} + +interface I2 : I { + override fun f(x: String): String + + override fun g(x: String): String + + override fun h(x: T): T +} + +open class A { + open fun f(x: String) = x + + open fun g(x: T) = x + + open fun h(x: String) = x +} + +class B : A(), I2 { + override val prop + get() = "3" +} + +fun box(): String { + val i: I = B() + var result = i.f() + i.g() + i.h() + if (result != "123") return "fail1: $result" + + val b = B() + result = b.f() + b.g() + b.h() + if (result != "123") return "fail2: $result" + + val a: A = B() + result = a.f("q") + a.g("w") + a.h("e") + if (result != "qwe") return "fail3: $result" + + 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 180241ae5ff..ee0527eb1fd 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 @@ -7122,6 +7122,30 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); } + @TestMetadata("implementedByFake2.kt") + public void testImplementedByFake2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/defaultArguments/implementedByFake2.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("implementedByFake3.kt") + public void testImplementedByFake3() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/defaultArguments/implementedByFake3.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + @TestMetadata("inheritedFromInterfaceViaAbstractSuperclass.kt") public void testInheritedFromInterfaceViaAbstractSuperclass() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/defaultArguments/inheritedFromInterfaceViaAbstractSuperclass.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 0486d9e4761..ab5681d8165 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -7122,6 +7122,30 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); } + @TestMetadata("implementedByFake2.kt") + public void testImplementedByFake2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/defaultArguments/implementedByFake2.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("implementedByFake3.kt") + public void testImplementedByFake3() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/defaultArguments/implementedByFake3.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + @TestMetadata("inheritedFromInterfaceViaAbstractSuperclass.kt") public void testInheritedFromInterfaceViaAbstractSuperclass() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/defaultArguments/inheritedFromInterfaceViaAbstractSuperclass.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index a2a0e05e0e6..9959f4c1bd2 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -7118,6 +7118,30 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); } + @TestMetadata("implementedByFake2.kt") + public void ignoreImplementedByFake2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/defaultArguments/implementedByFake2.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("implementedByFake3.kt") + public void ignoreImplementedByFake3() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/defaultArguments/implementedByFake3.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + public void testAllFilesPresentInDefaultArguments() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/defaultArguments"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } 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 2c120812de0..18eead615b0 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 @@ -7746,6 +7746,30 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { doTest(fileName); } + @TestMetadata("implementedByFake2.kt") + public void testImplementedByFake2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/defaultArguments/implementedByFake2.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("implementedByFake3.kt") + public void testImplementedByFake3() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/defaultArguments/implementedByFake3.kt"); + try { + doTest(fileName); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + @TestMetadata("inheritedFromInterfaceViaAbstractSuperclass.kt") public void testInheritedFromInterfaceViaAbstractSuperclass() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/defaultArguments/inheritedFromInterfaceViaAbstractSuperclass.kt");