From 60fdfb84416fd48c161e9e0a75d04a4654cfa9b3 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Thu, 23 Apr 2015 16:00:40 +0300 Subject: [PATCH] Bug fix: DataFlowInfo.getCompleteTypeInfo (with a test) --- .../smartcasts/DelegatingDataFlowInfo.java | 4 +-- .../varnotnull/assignNestedWhile.kt | 28 +++++++++++++++++++ .../varnotnull/assignNestedWhile.txt | 11 ++++++++ .../checkers/JetDiagnosticsTestGenerated.java | 6 ++++ 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/assignNestedWhile.kt create mode 100644 compiler/testData/diagnostics/tests/smartCasts/varnotnull/assignNestedWhile.txt 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 3391f074823..28bada2ee94 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 @@ -100,8 +100,8 @@ import static org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability.NOT_NULL result.putAll(key, info.typeInfo.get(key)); } } - if (valueWithGivenTypeInfo != null) { - withGivenTypeInfo.add(valueWithGivenTypeInfo); + if (info.valueWithGivenTypeInfo != null) { + withGivenTypeInfo.add(info.valueWithGivenTypeInfo); } info = (DelegatingDataFlowInfo) info.parent; } diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/assignNestedWhile.kt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/assignNestedWhile.kt new file mode 100644 index 00000000000..3d8e0df4d97 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/assignNestedWhile.kt @@ -0,0 +1,28 @@ +class Bar { + fun next(): Bar? { + if (2 == 4) + return this + else + return null + } +} + +fun foo(): Bar { + var x: Bar? = Bar() + var y: Bar? + y = Bar() + while (x != null) { + // Here call is unsafe because of inner loop + y.next() + while (y != null) { + if (x == y) + // x is not null because of outer while + return x + // y is not null because of inner while + y = y.next() + } + // x is not null because of outer while + x = x.next() + } + return Bar() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/varnotnull/assignNestedWhile.txt b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/assignNestedWhile.txt new file mode 100644 index 00000000000..765e649a5f1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/varnotnull/assignNestedWhile.txt @@ -0,0 +1,11 @@ +package + +internal fun foo(): Bar + +internal final class Bar { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + internal final fun next(): Bar? + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index 3397d45eae9..ebedb8470d4 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -11741,6 +11741,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/smartCasts/varnotnull"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("assignNestedWhile.kt") + public void testAssignNestedWhile() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/assignNestedWhile.kt"); + doTest(fileName); + } + @TestMetadata("assignment.kt") public void testAssignment() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/varnotnull/assignment.kt");