From fda89e9c72d57b7d40143397a26275ad8d4090dc Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Fri, 21 Jul 2017 11:59:04 +0300 Subject: [PATCH] Add test for KT-19128 It looks like the problem was caused by incorrect merging of StrictBasicValues and was fixed by commit 904c7f9c640ccb38c0becb40bd3b5dad3ac921bd. #KT-19128 Fixed --- .../box/checkcastOptimization/kt19128.kt | 26 +++++++++++++++++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 15 +++++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 15 +++++++++++ .../LightAnalysisModeTestGenerated.java | 15 +++++++++++ .../semantics/JsCodegenBoxTestGenerated.java | 15 +++++++++++ 5 files changed, 86 insertions(+) create mode 100644 compiler/testData/codegen/box/checkcastOptimization/kt19128.kt diff --git a/compiler/testData/codegen/box/checkcastOptimization/kt19128.kt b/compiler/testData/codegen/box/checkcastOptimization/kt19128.kt new file mode 100644 index 00000000000..07117907188 --- /dev/null +++ b/compiler/testData/codegen/box/checkcastOptimization/kt19128.kt @@ -0,0 +1,26 @@ +class A + +class B + +class C + +fun foo(parameters: Any?): Any? { + var payload: Any? = null + + if (parameters != null) { + if (parameters is A || parameters is B) { + payload = parameters + } else { + payload = "O" + } + } + + if (payload is String) { + payload += "K" + } + + return payload +} + +fun box(): String = + "${foo(C())}" \ 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 caee19fe08a..29197d307df 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 @@ -2709,6 +2709,21 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes } } + @TestMetadata("compiler/testData/codegen/box/checkcastOptimization") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class CheckcastOptimization extends AbstractIrBlackBoxCodegenTest { + public void testAllFilesPresentInCheckcastOptimization() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/checkcastOptimization"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); + } + + @TestMetadata("kt19128.kt") + public void testKt19128() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/checkcastOptimization/kt19128.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/box/classLiteral") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 29505ec4ae9..b700f8aeb02 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -2709,6 +2709,21 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { } } + @TestMetadata("compiler/testData/codegen/box/checkcastOptimization") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class CheckcastOptimization extends AbstractBlackBoxCodegenTest { + public void testAllFilesPresentInCheckcastOptimization() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/checkcastOptimization"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); + } + + @TestMetadata("kt19128.kt") + public void testKt19128() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/checkcastOptimization/kt19128.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/box/classLiteral") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index b4f1118b4ee..b686b931ba8 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -2709,6 +2709,21 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes } } + @TestMetadata("compiler/testData/codegen/box/checkcastOptimization") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class CheckcastOptimization extends AbstractLightAnalysisModeTest { + public void testAllFilesPresentInCheckcastOptimization() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/checkcastOptimization"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); + } + + @TestMetadata("kt19128.kt") + public void testKt19128() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/checkcastOptimization/kt19128.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/box/classLiteral") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) 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 ee75a75a52e..83686b2391d 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 @@ -3261,6 +3261,21 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { } } + @TestMetadata("compiler/testData/codegen/box/checkcastOptimization") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class CheckcastOptimization extends AbstractJsCodegenBoxTest { + public void testAllFilesPresentInCheckcastOptimization() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/checkcastOptimization"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); + } + + @TestMetadata("kt19128.kt") + public void testKt19128() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/checkcastOptimization/kt19128.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/codegen/box/classLiteral") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)