diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.java index b151931d407..6dfad095bfa 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.java @@ -145,7 +145,7 @@ import static org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability.NOT_NULL public Set getPossibleTypes(@NotNull DataFlowValue key) { KotlinType originalType = key.getType(); Set types = collectTypesFromMeAndParents(key); - if (getNullability(key).canBeNull()) { + if (getPredictableNullability(key).canBeNull()) { return types; } @@ -183,7 +183,7 @@ import static org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability.NOT_NULL @NotNull public DataFlowInfo assign(@NotNull DataFlowValue a, @NotNull DataFlowValue b) { Map nullability = Maps.newHashMap(); - Nullability nullabilityOfB = getNullability(b); + Nullability nullabilityOfB = getPredictableNullability(b); putNullability(nullability, a, nullabilityOfB); SetMultimap newTypeInfo = newTypeInfo(); @@ -208,8 +208,8 @@ import static org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability.NOT_NULL @NotNull public DataFlowInfo equate(@NotNull DataFlowValue a, @NotNull DataFlowValue b) { Map builder = Maps.newHashMap(); - Nullability nullabilityOfA = getNullability(a); - Nullability nullabilityOfB = getNullability(b); + Nullability nullabilityOfA = getPredictableNullability(a); + Nullability nullabilityOfB = getPredictableNullability(b); boolean changed = false; changed |= putNullability(builder, a, nullabilityOfA.refine(nullabilityOfB)); @@ -267,8 +267,8 @@ import static org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability.NOT_NULL @NotNull public DataFlowInfo disequate(@NotNull DataFlowValue a, @NotNull DataFlowValue b) { Map builder = Maps.newHashMap(); - Nullability nullabilityOfA = getNullability(a); - Nullability nullabilityOfB = getNullability(b); + Nullability nullabilityOfA = getPredictableNullability(a); + Nullability nullabilityOfB = getPredictableNullability(b); boolean changed = false; changed |= putNullability(builder, a, nullabilityOfA.refine(nullabilityOfB.invert())); diff --git a/compiler/testData/diagnostics/tests/smartCasts/unstableToStable.kt b/compiler/testData/diagnostics/tests/smartCasts/unstableToStable.kt new file mode 100644 index 00000000000..53baa677a91 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/unstableToStable.kt @@ -0,0 +1,18 @@ +class Foo(var x: Int?) { + init { + if (x != null) { + val y = x + // Error: x is not stable, Type(y) = Int? + x.hashCode() + y.hashCode() + if (y == x) { + // Still error + y.hashCode() + } + if (x == null && y != x) { + // Still error + y.hashCode() + } + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/unstableToStable.txt b/compiler/testData/diagnostics/tests/smartCasts/unstableToStable.txt new file mode 100644 index 00000000000..7809fea6c7b --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/unstableToStable.txt @@ -0,0 +1,9 @@ +package + +public final class Foo { + public constructor Foo(/*0*/ x: kotlin.Int?) + public final var x: kotlin.Int? + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 76deccfaa83..8b4e1932f8f 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -15060,6 +15060,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("unstableToStable.kt") + public void testUnstableToStable() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/unstableToStable.kt"); + doTest(fileName); + } + @TestMetadata("varChangedInInitializer.kt") public void testVarChangedInInitializer() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varChangedInInitializer.kt");