From fbc1d1a844c49a8b63dcd1339395b0015b735be4 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Fri, 28 Apr 2017 15:42:17 +0300 Subject: [PATCH] Clear var nullability in loops more accurately #KT-14977 Fixed --- .../calls/smartcasts/DelegatingDataFlowInfo.kt | 2 +- .../tests/senselessComparison/noExplicitType.kt | 15 +++++++++++++++ .../tests/senselessComparison/noExplicitType.txt | 5 +++++ .../kotlin/checkers/DiagnosticsTestGenerated.java | 6 ++++++ 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/tests/senselessComparison/noExplicitType.kt create mode 100644 compiler/testData/diagnostics/tests/senselessComparison/noExplicitType.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.kt index 822d359278d..5e2d340c97e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.kt @@ -146,7 +146,7 @@ internal class DelegatingDataFlowInfo private constructor( */ override fun clearValueInfo(value: DataFlowValue, languageVersionSettings: LanguageVersionSettings): DataFlowInfo { val builder = Maps.newHashMap() - putNullability(builder, value, Nullability.UNKNOWN, languageVersionSettings) + putNullability(builder, value, value.immanentNullability, languageVersionSettings) return create(this, ImmutableMap.copyOf(builder), EMPTY_TYPE_INFO, value) } diff --git a/compiler/testData/diagnostics/tests/senselessComparison/noExplicitType.kt b/compiler/testData/diagnostics/tests/senselessComparison/noExplicitType.kt new file mode 100644 index 00000000000..a094a2e60e8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/senselessComparison/noExplicitType.kt @@ -0,0 +1,15 @@ +fun readLine() = "x" + +fun foo() { + var line = "" + + while (line != null) { + line = readLine() + + if (line != null) { + bar() + } + } +} + +fun bar() {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/senselessComparison/noExplicitType.txt b/compiler/testData/diagnostics/tests/senselessComparison/noExplicitType.txt new file mode 100644 index 00000000000..af96f9548a8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/senselessComparison/noExplicitType.txt @@ -0,0 +1,5 @@ +package + +public fun bar(): kotlin.Unit +public fun foo(): kotlin.Unit +public fun readLine(): kotlin.String diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 294f6d0007c..a5d3e721156 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -19183,6 +19183,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/senselessComparison"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("noExplicitType.kt") + public void testNoExplicitType() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/senselessComparison/noExplicitType.kt"); + doTest(fileName); + } + @TestMetadata("parenthesized.kt") public void testParenthesized() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/senselessComparison/parenthesized.kt");