More correct handling of possible type set during assignment #KT-8229 Fixed

This commit is contained in:
Mikhail Glukhikh
2015-11-02 17:25:44 +03:00
parent bbea70a005
commit 03aaddd379
4 changed files with 48 additions and 1 deletions
@@ -175,7 +175,7 @@ import static org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability.NOT_NULL
putNullability(nullability, a, nullabilityOfB);
SetMultimap<DataFlowValue, KotlinType> newTypeInfo = newTypeInfo();
Set<KotlinType> typesForB = collectTypesFromMeAndParents(b);
Set<KotlinType> typesForB = getPossibleTypes(b);
// Own type of B must be recorded separately, e.g. for a constant
// But if its type is the same as A or it's null, there is no reason to do it
// because usually null type or own type are not saved in this set
@@ -0,0 +1,35 @@
fun foo(x: String) = x
fun test1() {
var c: Any? = "XXX"
if (c !is String) return
val newC: String? = "YYY"
if (newC != null) {
c = newC
}
foo(<!DEBUG_INFO_SMARTCAST!>c<!>)
}
fun test2() {
var c: Any? = "XXX"
if (c !is String) return
val newC: String? = "YYY"
if (newC is String) {
c = newC
}
foo(<!DEBUG_INFO_SMARTCAST!>c<!>)
}
fun test3() {
var c: Any? = "XXX"
if (c !is String) return
val newC: String? = "YYY"
if (newC == null) return
c = newC
foo(<!DEBUG_INFO_SMARTCAST!>c<!>)
}
@@ -0,0 +1,6 @@
package
public fun foo(/*0*/ x: kotlin.String): kotlin.String
public fun test1(): kotlin.Unit
public fun test2(): kotlin.Unit
public fun test3(): kotlin.Unit
@@ -15344,6 +15344,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("assignmentConversion.kt")
public void testAssignmentConversion() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/variables/assignmentConversion.kt");
doTest(fileName);
}
@TestMetadata("doWhileWithMiddleBreak.kt")
public void testDoWhileWithMiddleBreak() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/variables/doWhileWithMiddleBreak.kt");