[FIR] DFA fix: imply != null after x as? NotNullType for real variables

This commit is contained in:
Mikhail Glukhikh
2020-02-05 18:30:48 +03:00
parent 1bbcec4935
commit 1344d6407c
3 changed files with 5 additions and 6 deletions
@@ -211,10 +211,9 @@ abstract class FirDataFlowAnalyzer<FLOW : Flow>(
if (operandVariable.isReal()) { if (operandVariable.isReal()) {
flow.addImplication((expressionVariable notEq null) implies (operandVariable typeEq type)) flow.addImplication((expressionVariable notEq null) implies (operandVariable typeEq type))
flow.addImplication((expressionVariable eq null) implies (operandVariable typeNotEq type)) flow.addImplication((expressionVariable eq null) implies (operandVariable typeNotEq type))
} else { }
if (type.nullability == ConeNullability.NOT_NULL) { if (type.nullability == ConeNullability.NOT_NULL) {
flow.addImplication((expressionVariable notEq null) implies (operandVariable notEq null)) flow.addImplication((expressionVariable notEq null) implies (operandVariable notEq null))
}
} }
} }
@@ -40,7 +40,7 @@ fun test4(x: SomeClass?) {
fun test5(x: AnotherClass?) { fun test5(x: AnotherClass?) {
val bar = x?.bar as? String ?: return val bar = x?.bar as? String ?: return
x.<!INAPPLICABLE_CANDIDATE!>foo<!> x.foo
} }
fun test6(x: SomeClass?) { fun test6(x: SomeClass?) {
@@ -67,7 +67,7 @@ FILE: test.kt
} }
} }
R|<local>/x|.<Inapplicable(WRONG_RECEIVER): [/AnotherClass.foo]># R|<local>/x|.R|/AnotherClass.foo|
} }
public final fun test6(x: R|SomeClass?|): R|kotlin/Unit| { public final fun test6(x: R|SomeClass?|): R|kotlin/Unit| {
lval bar: R|kotlin/String| = when (lval <elvis>: R|kotlin/String?| = (R|<local>/x|?.R|/SomeClass.bar| as? R|kotlin/String|)) { lval bar: R|kotlin/String| = when (lval <elvis>: R|kotlin/String?| = (R|<local>/x|?.R|/SomeClass.bar| as? R|kotlin/String|)) {