From aa5b63d8d76e2e7dbf1714424a18c0812f7853ff Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 13 Jan 2015 16:31:09 +0100 Subject: [PATCH] dfa: type values shouldn't be part of equivalence relations (IDEA-135134) --- .../dataFlow/DfaMemoryStateImpl.java | 3 +++ .../dataFlow/fixture/DontSaveTypeValue.java | 22 +++++++++++++++++++ .../DataFlowInspectionTest.java | 1 + 3 files changed, 26 insertions(+) create mode 100644 java/java-tests/testData/inspection/dataFlow/fixture/DontSaveTypeValue.java diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java index a1a1f142d1a3..de019dad0cd5 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java @@ -267,6 +267,9 @@ public class DfaMemoryStateImpl implements DfaMemoryState { if (!canBeReused(dfaValue) && !(((DfaBoxedValue)dfaValue).getWrappedValue() instanceof DfaConstValue)) { return null; } + if (dfaValue instanceof DfaTypeValue) { + return null; + } EqClass aClass = new EqClass(myFactory); aClass.add(dfaValue.getID()); diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/DontSaveTypeValue.java b/java/java-tests/testData/inspection/dataFlow/fixture/DontSaveTypeValue.java new file mode 100644 index 000000000000..d1ed8938ab09 --- /dev/null +++ b/java/java-tests/testData/inspection/dataFlow/fixture/DontSaveTypeValue.java @@ -0,0 +1,22 @@ +import org.jetbrains.annotations.*; + +class TestIDEAWarn { + public int bar() { + if (Foo.BAR == foo(0)) { + return -1; + } + else if (Foo.BAR == foo(1)) { + return 1; + } + + return 0; + } + + @NotNull + private native Foo foo(int a); + + enum Foo { + FOO, BAR + } + +} \ 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 1854cd23bf60..e22fb0d71d13 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionTest.java @@ -95,6 +95,7 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase { public void testSwitchEnumConstant() { doTest(); } public void testEnumConstantNotNull() throws Throwable { doTest(); } public void testEqualsConstant() throws Throwable { doTest(); } + public void testDontSaveTypeValue() { doTest(); } public void testFinalLoopVariableInstanceof() throws Throwable { doTest(); } public void testGreaterIsNotEquals() throws Throwable { doTest(); } public void testNotGreaterIsNotEquals() throws Throwable { doTest(); }