From 59b1743c37d894b67d17fd33fb6f97d24f64a24a Mon Sep 17 00:00:00 2001 From: Roman Artemev Date: Fri, 19 Oct 2018 19:26:26 +0300 Subject: [PATCH] Add tests --- .../codegen/box/typeMapping/nullNothing.kt | 4 +++ .../codegen/BlackBoxCodegenTestGenerated.java | 5 +++ .../LightAnalysisModeTestGenerated.java | 5 +++ .../ir/IrBlackBoxCodegenTestGenerated.java | 5 +++ .../js/test/semantics/BoxJsTestGenerated.java | 5 +++ .../test/semantics/IrBoxJsTestGenerated.java | 5 +++ .../IrJsCodegenBoxTestGenerated.java | 5 +++ .../semantics/JsCodegenBoxTestGenerated.java | 5 +++ .../evaluationOrder/throwableDelegation.kt | 36 +++++++++++++++++++ 9 files changed, 75 insertions(+) create mode 100644 compiler/testData/codegen/box/typeMapping/nullNothing.kt create mode 100644 js/js.translator/testData/box/expression/evaluationOrder/throwableDelegation.kt diff --git a/compiler/testData/codegen/box/typeMapping/nullNothing.kt b/compiler/testData/codegen/box/typeMapping/nullNothing.kt new file mode 100644 index 00000000000..69a70f44262 --- /dev/null +++ b/compiler/testData/codegen/box/typeMapping/nullNothing.kt @@ -0,0 +1,4 @@ +fun box(): String { + // kotlin.Nothing should not be loaded here + return (if (null is Nothing?) "O" else "FAIL1") + (if (null !is Nothing) "K" else "FAIL2") +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 5d2f3a138b5..c6bc6ade710 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -23595,6 +23595,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/typeMapping/nothing.kt"); } + @TestMetadata("nullNothing.kt") + public void testNullNothing() throws Exception { + runTest("compiler/testData/codegen/box/typeMapping/nullNothing.kt"); + } + @TestMetadata("nullableNothing.kt") public void testNullableNothing() throws Exception { runTest("compiler/testData/codegen/box/typeMapping/nullableNothing.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 2c4beb9aa78..627cca2c805 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -23595,6 +23595,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/typeMapping/nothing.kt"); } + @TestMetadata("nullNothing.kt") + public void testNullNothing() throws Exception { + runTest("compiler/testData/codegen/box/typeMapping/nullNothing.kt"); + } + @TestMetadata("nullableNothing.kt") public void testNullableNothing() throws Exception { runTest("compiler/testData/codegen/box/typeMapping/nullableNothing.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 5134c7cbfd8..7e872bc028a 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -23600,6 +23600,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/typeMapping/nothing.kt"); } + @TestMetadata("nullNothing.kt") + public void testNullNothing() throws Exception { + runTest("compiler/testData/codegen/box/typeMapping/nullNothing.kt"); + } + @TestMetadata("nullableNothing.kt") public void testNullableNothing() throws Exception { runTest("compiler/testData/codegen/box/typeMapping/nullableNothing.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java index 1de8b860b44..d5f93db39a7 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java @@ -2229,6 +2229,11 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest { runTest("js/js.translator/testData/box/expression/evaluationOrder/singleComponentDestructuring.kt"); } + @TestMetadata("throwableDelegation.kt") + public void testThrowableDelegation() throws Exception { + runTest("js/js.translator/testData/box/expression/evaluationOrder/throwableDelegation.kt"); + } + @TestMetadata("whenAsMinusArgument.kt") public void testWhenAsMinusArgument() throws Exception { runTest("js/js.translator/testData/box/expression/evaluationOrder/whenAsMinusArgument.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrBoxJsTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrBoxJsTestGenerated.java index 1c7bbe5e21a..b17390c84f5 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrBoxJsTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrBoxJsTestGenerated.java @@ -2229,6 +2229,11 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { runTest("js/js.translator/testData/box/expression/evaluationOrder/singleComponentDestructuring.kt"); } + @TestMetadata("throwableDelegation.kt") + public void testThrowableDelegation() throws Exception { + runTest("js/js.translator/testData/box/expression/evaluationOrder/throwableDelegation.kt"); + } + @TestMetadata("whenAsMinusArgument.kt") public void testWhenAsMinusArgument() throws Exception { runTest("js/js.translator/testData/box/expression/evaluationOrder/whenAsMinusArgument.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java index c6f44e0b03d..79e3901d3c9 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/IrJsCodegenBoxTestGenerated.java @@ -20770,6 +20770,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/typeMapping/nothing.kt"); } + @TestMetadata("nullNothing.kt") + public void testNullNothing() throws Exception { + runTest("compiler/testData/codegen/box/typeMapping/nullNothing.kt"); + } + @TestMetadata("nullableNothing.kt") public void testNullableNothing() throws Exception { runTest("compiler/testData/codegen/box/typeMapping/nullableNothing.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 f23704e4a6c..921eae9ebbe 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 @@ -21815,6 +21815,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/typeMapping/nothing.kt"); } + @TestMetadata("nullNothing.kt") + public void testNullNothing() throws Exception { + runTest("compiler/testData/codegen/box/typeMapping/nullNothing.kt"); + } + @TestMetadata("nullableNothing.kt") public void testNullableNothing() throws Exception { runTest("compiler/testData/codegen/box/typeMapping/nullableNothing.kt"); diff --git a/js/js.translator/testData/box/expression/evaluationOrder/throwableDelegation.kt b/js/js.translator/testData/box/expression/evaluationOrder/throwableDelegation.kt new file mode 100644 index 00000000000..85338a7ca99 --- /dev/null +++ b/js/js.translator/testData/box/expression/evaluationOrder/throwableDelegation.kt @@ -0,0 +1,36 @@ +// IGNORE_BACKEND: JS +// EXPECTED_REACHABLE_NODES: 1298 +package foo + +fun check(e: Throwable, expectedString: String) { + try { + throw e + } + catch (e: Throwable) { + assertEquals(expectedString, e.toString()) + } +} + +var storage = "" + +fun sideEffect(v: String, m: T?): T? { + storage += v + return m +} + +class MyException1(i1: String, i2: String, m: String? = null, t: Throwable? = null): Throwable(sideEffect(i2, sideEffect(i1, m)), t) +class MyException2(i1: String, i2: String, m: String? = null, t: Throwable? = null): Throwable(sideEffect(i1, m), sideEffect(i2, t)) + + +fun box(): String { + check(MyException1("1", "2"), "MyException1: null") + check(MyException1("3", "4", "aaa"), "MyException1: aaa") + check(MyException1("5", "6", t = Throwable("bbb")), "MyException1: Throwable: bbb") + check(MyException2("7", "8"), "MyException2: null") + check(MyException2("9", "0", "ccc"), "MyException2: ccc") + check(MyException2("A", "B", t = Throwable("ddd")), "MyException2: Throwable: ddd") + + if (storage != "1234567890AB") return "FAIL $storage" + + return "OK" +}