From cd6934bee8ed8f95c68cffd3753910fa611c652f Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Mon, 9 Dec 2013 17:07:47 +0400 Subject: [PATCH] fixed bug in 'DataFlowInfo.getPossibleTypes' parent types should be enriched as well --- .../resolve/calls/autocasts/DelegatingDataFlowInfo.java | 7 ++++--- .../nullabilityAndAutoCasts/dataFlowInfoAfterExclExcl.kt | 8 ++++++++ .../jet/checkers/JetDiagnosticsTestGenerated.java | 5 +++++ 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/dataFlowInfoAfterExclExcl.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/DelegatingDataFlowInfo.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/DelegatingDataFlowInfo.java index 4c63b410192..7a4879ce141 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/DelegatingDataFlowInfo.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/DelegatingDataFlowInfo.java @@ -102,9 +102,10 @@ import static org.jetbrains.jet.lang.resolve.calls.autocasts.Nullability.NOT_NUL @Override @NotNull public Set getPossibleTypes(@NotNull DataFlowValue key) { - Set types = typeInfo.get(key); + Set theseTypes = typeInfo.get(key); + Set types = parent == null ? theseTypes : Sets.union(theseTypes, parent.getPossibleTypes(key)); if (getNullability(key).canBeNull()) { - return parent == null ? types : Sets.union(types, parent.getPossibleTypes(key)); + return types; } Set enrichedTypes = Sets.newHashSetWithExpectedSize(types.size() + 1); @@ -116,7 +117,7 @@ import static org.jetbrains.jet.lang.resolve.calls.autocasts.Nullability.NOT_NUL enrichedTypes.add(TypeUtils.makeNotNullable(type)); } - return parent == null ? enrichedTypes : Sets.union(enrichedTypes, parent.getPossibleTypes(key)); + return enrichedTypes; } @Override diff --git a/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/dataFlowInfoAfterExclExcl.kt b/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/dataFlowInfoAfterExclExcl.kt new file mode 100644 index 00000000000..dd609f3a18c --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/dataFlowInfoAfterExclExcl.kt @@ -0,0 +1,8 @@ +fun foo(d: Any?) { + if (d is String?) { + d!! + doString(d) + } +} + +fun doString(s: String) = s \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index b9b09e24b29..82f439812c0 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -4577,6 +4577,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/AssertNotNull.kt"); } + @TestMetadata("dataFlowInfoAfterExclExcl.kt") + public void testDataFlowInfoAfterExclExcl() throws Exception { + doTest("compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/dataFlowInfoAfterExclExcl.kt"); + } + @TestMetadata("equalityUnderNotNullCheck.kt") public void testEqualityUnderNotNullCheck() throws Exception { doTest("compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/equalityUnderNotNullCheck.kt");