From 16505daeea236ce908bb34ab49b138572253a5ef Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Mon, 3 Jul 2017 14:08:15 +0300 Subject: [PATCH] Fix 'equals' for NotNullBasicValue NotNullBasicValues were merged incorrectly sometimes, which caused problems with INSTANCEOF checks. #KT-18779 Fixed --- .../nullCheck/nullabilityValues.kt | 2 +- .../codegen/box/regressions/kt18779.kt | 19 +++++++++++++++++++ .../ir/IrBlackBoxCodegenTestGenerated.java | 6 ++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 6 ++++++ .../LightAnalysisModeTestGenerated.java | 6 ++++++ .../semantics/JsCodegenBoxTestGenerated.java | 6 ++++++ 6 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/codegen/box/regressions/kt18779.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/nullCheck/nullabilityValues.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/nullCheck/nullabilityValues.kt index 24ef3a5ffa2..9800b8b4d6d 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/nullCheck/nullabilityValues.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/nullCheck/nullabilityValues.kt @@ -23,7 +23,7 @@ import org.jetbrains.org.objectweb.asm.Type import org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue class NotNullBasicValue(type: Type?) : StrictBasicValue(type) { - override fun equals(other: Any?): Boolean = other is NotNullBasicValue + override fun equals(other: Any?): Boolean = other is NotNullBasicValue && other.type == type // We do not differ not-nullable values, so we should always return the same hashCode // Actually it doesn't really matter because analyzer is not supposed to store values in hashtables override fun hashCode() = 0 diff --git a/compiler/testData/codegen/box/regressions/kt18779.kt b/compiler/testData/codegen/box/regressions/kt18779.kt new file mode 100644 index 00000000000..986fc495998 --- /dev/null +++ b/compiler/testData/codegen/box/regressions/kt18779.kt @@ -0,0 +1,19 @@ +sealed class Result { + class Failure(val exception: Exception) : Result() + class Success(val message: String) : Result() +} + +fun box(): String { + var result: Result + try { + result = Result.Success("OK") + } + catch (e: Exception) { + result = Result.Failure(Exception()) + } + + when (result) { + is Result.Failure -> throw result.exception + is Result.Success -> return result.message + } +} \ 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 b9a6cb48568..755d276cf64 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 @@ -16229,6 +16229,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("kt18779.kt") + public void testKt18779() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/kt18779.kt"); + doTest(fileName); + } + @TestMetadata("kt1932.kt") public void testKt1932() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/kt1932.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index b8b646bf2e1..0d2105dcda8 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -16229,6 +16229,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("kt18779.kt") + public void testKt18779() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/kt18779.kt"); + doTest(fileName); + } + @TestMetadata("kt1932.kt") public void testKt1932() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/kt1932.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 199c1b12213..8a561b96284 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -16229,6 +16229,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes doTest(fileName); } + @TestMetadata("kt18779.kt") + public void testKt18779() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/kt18779.kt"); + doTest(fileName); + } + @TestMetadata("kt1932.kt") public void testKt1932() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/kt1932.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 4322497dded..c743766c697 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 @@ -19895,6 +19895,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { doTest(fileName); } + @TestMetadata("kt18779.kt") + public void testKt18779() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/kt18779.kt"); + doTest(fileName); + } + @TestMetadata("kt1932.kt") public void testKt1932() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/regressions/kt1932.kt");