Clear var nullability in loops more accurately #KT-14977 Fixed

This commit is contained in:
Mikhail Glukhikh
2017-04-28 15:42:17 +03:00
committed by Mikhail Glukhikh
parent dc3ea4b6e4
commit fbc1d1a844
4 changed files with 27 additions and 1 deletions
@@ -146,7 +146,7 @@ internal class DelegatingDataFlowInfo private constructor(
*/
override fun clearValueInfo(value: DataFlowValue, languageVersionSettings: LanguageVersionSettings): DataFlowInfo {
val builder = Maps.newHashMap<DataFlowValue, Nullability>()
putNullability(builder, value, Nullability.UNKNOWN, languageVersionSettings)
putNullability(builder, value, value.immanentNullability, languageVersionSettings)
return create(this, ImmutableMap.copyOf(builder), EMPTY_TYPE_INFO, value)
}
@@ -0,0 +1,15 @@
fun readLine() = "x"
fun foo() {
var line = ""
while (<!SENSELESS_COMPARISON!>line != null<!>) {
line = readLine()
if (<!SENSELESS_COMPARISON!>line != null<!>) {
bar()
}
}
}
fun bar() {}
@@ -0,0 +1,5 @@
package
public fun bar(): kotlin.Unit
public fun foo(): kotlin.Unit
public fun readLine(): kotlin.String
@@ -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");