From 88df6b0e2b2f763a2063e9110f25b4ff7908efb9 Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 17 Sep 2013 17:48:54 +0400 Subject: [PATCH] fix dfa false positive in JSTypeofTypeImpl --- .../dataFlow/value/DfaTypeValue.java | 3 +-- ...usionWithAnonymousConstantInitializer.java | 24 +++++++++++++++++++ .../DataFlowInspectionTest.java | 1 + 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 java/java-tests/testData/inspection/dataFlow/fixture/NoConfusionWithAnonymousConstantInitializer.java diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaTypeValue.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaTypeValue.java index 06022394a19c..f7b648762365 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaTypeValue.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaTypeValue.java @@ -25,7 +25,6 @@ package com.intellij.codeInspection.dataFlow.value; import com.intellij.codeInspection.dataFlow.Nullness; -import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiKeyword; import com.intellij.psi.PsiType; @@ -109,7 +108,7 @@ public class DfaTypeValue extends DfaValue { } private boolean hardEquals(DfaTypeValue aType) { - return Comparing.equal(myCanonicalText, aType.myCanonicalText) && myNullness == aType.myNullness; + return myCanonicalText.equals(aType.myCanonicalText) && myNullness == aType.myNullness && myType.equals(aType.myType); } public boolean isAssignableFrom(DfaTypeValue dfaType) { diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/NoConfusionWithAnonymousConstantInitializer.java b/java/java-tests/testData/inspection/dataFlow/fixture/NoConfusionWithAnonymousConstantInitializer.java new file mode 100644 index 000000000000..5a71e43f2c5d --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/fixture/NoConfusionWithAnonymousConstantInitializer.java @@ -0,0 +1,24 @@ +import org.jetbrains.annotations.NotNull; + +interface JSType { +} +class JSTypeofTypeImpl implements JSType { + static final JSType NO_TYPE = new JSType() { + }; + private JSType myEvaluatedType; + private void evaluateType() { + JSType exprType = JSResolveUtil.getExpressionJSType(); + if (exprType instanceof JSTypeofTypeImpl) { + } + myEvaluatedType = NO_TYPE; + } + +} + +class JSResolveUtil { + + @NotNull + public static JSType getExpressionJSType() { + return JSTypeofTypeImpl.NO_TYPE; + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java index 746a6c57ea28..b0df0fb12b85 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java @@ -294,6 +294,7 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase { public void testUnconditionalForLoop() { doTest(); } public void testAnonymousMethodIndependence() { doTest(); } public void testAnonymousFieldIndependence() { doTest(); } + public void testNoConfusionWithAnonymousConstantInitializer() { doTest(); } public void _testNullCheckBeforeInstanceof() { doTest(); } }