From 7e808bd3ea49b8b53faf76e62bdfd83a347e6808 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Tue, 3 Oct 2017 15:42:12 +0300 Subject: [PATCH] Add more tests for constructor call evaluation order - break in arguments - continue in arguments - early return in arguments - non-local return in arguments - nested constructor call in arguments --- .../breakInConstructorArguments.kt | 39 +++++++++++++++++ .../continueInConstructorArguments.kt | 40 +++++++++++++++++ .../earlyReturnInConstructorArguments.kt | 41 ++++++++++++++++++ ...orCallWithJumpOutInConstructorArguments.kt | 36 ++++++++++++++++ .../nonLocalReturnInConstructorArguments.kt | 43 +++++++++++++++++++ ...ssiblyPoppedUnitializedValueInArguments.kt | 36 ++++++++++++++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 36 ++++++++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 36 ++++++++++++++++ .../LightAnalysisModeTestGenerated.java | 36 ++++++++++++++++ 9 files changed, 343 insertions(+) create mode 100644 compiler/testData/codegen/box/constructorCall/breakInConstructorArguments.kt create mode 100644 compiler/testData/codegen/box/constructorCall/continueInConstructorArguments.kt create mode 100644 compiler/testData/codegen/box/constructorCall/earlyReturnInConstructorArguments.kt create mode 100644 compiler/testData/codegen/box/constructorCall/nestedConstructorCallWithJumpOutInConstructorArguments.kt create mode 100644 compiler/testData/codegen/box/constructorCall/nonLocalReturnInConstructorArguments.kt create mode 100644 compiler/testData/codegen/box/constructorCall/possiblyPoppedUnitializedValueInArguments.kt diff --git a/compiler/testData/codegen/box/constructorCall/breakInConstructorArguments.kt b/compiler/testData/codegen/box/constructorCall/breakInConstructorArguments.kt new file mode 100644 index 00000000000..13e8ce2d951 --- /dev/null +++ b/compiler/testData/codegen/box/constructorCall/breakInConstructorArguments.kt @@ -0,0 +1,39 @@ +// TARGET_BACKEND: JVM +// WITH_RUNTIME +// FILE: test.kt +fun box(): String { + var count = 0 + while (true) { + Foo( + logged("i", if (count == 0) 1 else break), + logged("j", 2) + ) + count++ + } + + val result = log.toString() + if (result != "ij") return "Fail: '$result'" + + return "OK" +} + +// FILE: util.kt +val log = StringBuilder() + +fun logged(msg: String, value: T): T { + log.append(msg) + return value +} + +// FILE: Foo.kt +class Foo(i: Int, j: Int) { + init { + log.append("") + } + + companion object { + init { + log.append("") + } + } +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/constructorCall/continueInConstructorArguments.kt b/compiler/testData/codegen/box/constructorCall/continueInConstructorArguments.kt new file mode 100644 index 00000000000..52d81e4f22c --- /dev/null +++ b/compiler/testData/codegen/box/constructorCall/continueInConstructorArguments.kt @@ -0,0 +1,40 @@ +// TARGET_BACKEND: JVM +// WITH_RUNTIME +// FILE: test.kt +fun box(): String { + var count = 0 + while (true) { + count++ + if (count > 1) break + Foo( + logged("i", if (count == 1) 1 else continue), + logged("j", 2) + ) + } + + val result = log.toString() + if (result != "ij") return "Fail: '$result'" + + return "OK" +} + +// FILE: util.kt +val log = StringBuilder() + +fun logged(msg: String, value: T): T { + log.append(msg) + return value +} + +// FILE: Foo.kt +class Foo(i: Int, j: Int) { + init { + log.append("") + } + + companion object { + init { + log.append("") + } + } +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/constructorCall/earlyReturnInConstructorArguments.kt b/compiler/testData/codegen/box/constructorCall/earlyReturnInConstructorArguments.kt new file mode 100644 index 00000000000..3497418bfb0 --- /dev/null +++ b/compiler/testData/codegen/box/constructorCall/earlyReturnInConstructorArguments.kt @@ -0,0 +1,41 @@ +// TARGET_BACKEND: JVM +// WITH_RUNTIME +inline fun ok(): String { + return foo(1, 1.0, 1.0f, 1L, "O", C(if (bar()) return "zap" else "K")) +} + +fun box(): String { + val ok = ok() + if (ok != "OK") return "Fail: $ok" + + val r = log.toString() + if (r != ";bar;;foo;") return "Fail: '$r'" + + return "OK" +} + +// FILE: C.kt +class C(val str: String) { + init { + log.append(";") + } + + companion object { + init { + log.append(";") + } + } +} + +// FILE: util.kt +fun foo(x: Int, a: Double, b: Float, y: Long, z: String, c: C) = + logged("foo;", z + c.str) + +fun bar() = logged("bar;", false) + +val log = StringBuilder() + +fun logged(msg: String, value: T): T { + log.append(msg) + return value +} diff --git a/compiler/testData/codegen/box/constructorCall/nestedConstructorCallWithJumpOutInConstructorArguments.kt b/compiler/testData/codegen/box/constructorCall/nestedConstructorCallWithJumpOutInConstructorArguments.kt new file mode 100644 index 00000000000..151cc983141 --- /dev/null +++ b/compiler/testData/codegen/box/constructorCall/nestedConstructorCallWithJumpOutInConstructorArguments.kt @@ -0,0 +1,36 @@ +// TARGET_BACKEND: JVM +// WITH_RUNTIME +// FILE: test.kt +fun box(): String { + for (count in 0..3) { + val test = Foo(count, Foo(1, "x", 2), if (count > 0) break else 3) + if (count > 0) return "Fail: count = $count" + if (test.toString() != "Foo(0,Foo(1,x,2),3)") return "Fail: ${test.toString()}" + } + + return "OK" +} + + +// FILE: util.kt +val log = StringBuilder() + +fun logged(msg: String, value: T): T { + log.append(msg) + return value +} + +// FILE: Foo.kt +class Foo(val a: Int, val b: Any, val c: Int) { + init { + log.append("") + } + + override fun toString() = "Foo($a,$b,$c)" + + companion object { + init { + log.append("") + } + } +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/constructorCall/nonLocalReturnInConstructorArguments.kt b/compiler/testData/codegen/box/constructorCall/nonLocalReturnInConstructorArguments.kt new file mode 100644 index 00000000000..a70e2a8a4ec --- /dev/null +++ b/compiler/testData/codegen/box/constructorCall/nonLocalReturnInConstructorArguments.kt @@ -0,0 +1,43 @@ +// TARGET_BACKEND: JVM +// WITH_RUNTIME +// FILE: test.kt +fun box(): String { + run L1@{ + var count = 0 + run { + while (true) { + Foo( + logged("i", if (count == 0) 1 else return@L1), + logged("j", 2) + ) + count++ + } + } + } + + val result = log.toString() + if (result != "ij") return "Fail: '$result'" + + return "OK" +} + +// FILE: util.kt +val log = StringBuilder() + +fun logged(msg: String, value: T): T { + log.append(msg) + return value +} + +// FILE: Foo.kt +class Foo(i: Int, j: Int) { + init { + log.append("") + } + + companion object { + init { + log.append("") + } + } +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/constructorCall/possiblyPoppedUnitializedValueInArguments.kt b/compiler/testData/codegen/box/constructorCall/possiblyPoppedUnitializedValueInArguments.kt new file mode 100644 index 00000000000..d889fb109ff --- /dev/null +++ b/compiler/testData/codegen/box/constructorCall/possiblyPoppedUnitializedValueInArguments.kt @@ -0,0 +1,36 @@ +// TARGET_BACKEND: JVM +// WITH_RUNTIME +// FILE: test.kt +fun box(): String { + for (count in 0..3) { + val test = Foo(count, Foo(1, "x", if (count > 0) break else 2), 3) + if (count > 0) return "Fail: count = $count" + if (test.toString() != "Foo(0,Foo(1,x,2),3)") return "Fail: ${test.toString()}" + } + + return "OK" +} + + +// FILE: util.kt +val log = StringBuilder() + +fun logged(msg: String, value: T): T { + log.append(msg) + return value +} + +// FILE: Foo.kt +class Foo(val a: Int, val b: Any, val c: Int) { + init { + log.append("") + } + + override fun toString() = "Foo($a,$b,$c)" + + companion object { + init { + log.append("") + } + } +} \ 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 f6291712956..166c935de04 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 @@ -4283,6 +4283,24 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/constructorCall"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("breakInConstructorArguments.kt") + public void testBreakInConstructorArguments() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/constructorCall/breakInConstructorArguments.kt"); + doTest(fileName); + } + + @TestMetadata("continueInConstructorArguments.kt") + public void testContinueInConstructorArguments() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/constructorCall/continueInConstructorArguments.kt"); + doTest(fileName); + } + + @TestMetadata("earlyReturnInConstructorArguments.kt") + public void testEarlyReturnInConstructorArguments() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/constructorCall/earlyReturnInConstructorArguments.kt"); + doTest(fileName); + } + @TestMetadata("inlineFunInConstructorCallEvaluationOrder.kt") public void testInlineFunInConstructorCallEvaluationOrder() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/constructorCall/inlineFunInConstructorCallEvaluationOrder.kt"); @@ -4301,6 +4319,24 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("nestedConstructorCallWithJumpOutInConstructorArguments.kt") + public void testNestedConstructorCallWithJumpOutInConstructorArguments() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/constructorCall/nestedConstructorCallWithJumpOutInConstructorArguments.kt"); + doTest(fileName); + } + + @TestMetadata("nonLocalReturnInConstructorArguments.kt") + public void testNonLocalReturnInConstructorArguments() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/constructorCall/nonLocalReturnInConstructorArguments.kt"); + doTest(fileName); + } + + @TestMetadata("possiblyPoppedUnitializedValueInArguments.kt") + public void testPossiblyPoppedUnitializedValueInArguments() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/constructorCall/possiblyPoppedUnitializedValueInArguments.kt"); + doTest(fileName); + } + @TestMetadata("regularConstructorCallEvaluationOrder.kt") public void testRegularConstructorCallEvaluationOrder() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/constructorCall/regularConstructorCallEvaluationOrder.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 5f2f71a4e58..3faebe099e0 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -4283,6 +4283,24 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/constructorCall"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("breakInConstructorArguments.kt") + public void testBreakInConstructorArguments() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/constructorCall/breakInConstructorArguments.kt"); + doTest(fileName); + } + + @TestMetadata("continueInConstructorArguments.kt") + public void testContinueInConstructorArguments() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/constructorCall/continueInConstructorArguments.kt"); + doTest(fileName); + } + + @TestMetadata("earlyReturnInConstructorArguments.kt") + public void testEarlyReturnInConstructorArguments() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/constructorCall/earlyReturnInConstructorArguments.kt"); + doTest(fileName); + } + @TestMetadata("inlineFunInConstructorCallEvaluationOrder.kt") public void testInlineFunInConstructorCallEvaluationOrder() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/constructorCall/inlineFunInConstructorCallEvaluationOrder.kt"); @@ -4301,6 +4319,24 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("nestedConstructorCallWithJumpOutInConstructorArguments.kt") + public void testNestedConstructorCallWithJumpOutInConstructorArguments() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/constructorCall/nestedConstructorCallWithJumpOutInConstructorArguments.kt"); + doTest(fileName); + } + + @TestMetadata("nonLocalReturnInConstructorArguments.kt") + public void testNonLocalReturnInConstructorArguments() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/constructorCall/nonLocalReturnInConstructorArguments.kt"); + doTest(fileName); + } + + @TestMetadata("possiblyPoppedUnitializedValueInArguments.kt") + public void testPossiblyPoppedUnitializedValueInArguments() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/constructorCall/possiblyPoppedUnitializedValueInArguments.kt"); + doTest(fileName); + } + @TestMetadata("regularConstructorCallEvaluationOrder.kt") public void testRegularConstructorCallEvaluationOrder() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/constructorCall/regularConstructorCallEvaluationOrder.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 72d132ee0d3..6b209eec632 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -4283,6 +4283,24 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/constructorCall"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); } + @TestMetadata("breakInConstructorArguments.kt") + public void testBreakInConstructorArguments() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/constructorCall/breakInConstructorArguments.kt"); + doTest(fileName); + } + + @TestMetadata("continueInConstructorArguments.kt") + public void testContinueInConstructorArguments() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/constructorCall/continueInConstructorArguments.kt"); + doTest(fileName); + } + + @TestMetadata("earlyReturnInConstructorArguments.kt") + public void testEarlyReturnInConstructorArguments() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/constructorCall/earlyReturnInConstructorArguments.kt"); + doTest(fileName); + } + @TestMetadata("inlineFunInConstructorCallEvaluationOrder.kt") public void testInlineFunInConstructorCallEvaluationOrder() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/constructorCall/inlineFunInConstructorCallEvaluationOrder.kt"); @@ -4301,6 +4319,24 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes doTest(fileName); } + @TestMetadata("nestedConstructorCallWithJumpOutInConstructorArguments.kt") + public void testNestedConstructorCallWithJumpOutInConstructorArguments() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/constructorCall/nestedConstructorCallWithJumpOutInConstructorArguments.kt"); + doTest(fileName); + } + + @TestMetadata("nonLocalReturnInConstructorArguments.kt") + public void testNonLocalReturnInConstructorArguments() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/constructorCall/nonLocalReturnInConstructorArguments.kt"); + doTest(fileName); + } + + @TestMetadata("possiblyPoppedUnitializedValueInArguments.kt") + public void testPossiblyPoppedUnitializedValueInArguments() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/constructorCall/possiblyPoppedUnitializedValueInArguments.kt"); + doTest(fileName); + } + @TestMetadata("regularConstructorCallEvaluationOrder.kt") public void testRegularConstructorCallEvaluationOrder() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/constructorCall/regularConstructorCallEvaluationOrder.kt");