IDEA-136580 "Contract violation" warnings are reported for manual method contract phpstorm/140.2503
authorpeter <peter@jetbrains.com>
Mon, 16 Feb 2015 11:12:04 +0000 (12:12 +0100)
committerpeter <peter@jetbrains.com>
Mon, 16 Feb 2015 11:13:26 +0000 (12:13 +0100)
java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DfaMemoryStateImpl.java
java/java-tests/testData/inspection/dataFlow/contractCheck/DoubleParameter.java [new file with mode: 0644]
java/java-tests/testSrc/com/intellij/codeInspection/ContractCheckTest.java

index e914c50278f9145f8fea4cb94eecc80483ae06ab..56bf0f301195cd744cb6e395f83d3c2be6f5011c 100644 (file)
@@ -625,7 +625,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
       applyEquivalenceRelation(dfaRelation, dfaLeft, dfaRight);
       return isNegated;
     }
-    if (canBeNaN(dfaLeft) || canBeNaN(dfaRight)) {
+    if (canBeNaN(dfaLeft) && canBeNaN(dfaRight)) {
       applyEquivalenceRelation(dfaRelation, dfaLeft, dfaRight);
       return true;
     }
diff --git a/java/java-tests/testData/inspection/dataFlow/contractCheck/DoubleParameter.java b/java/java-tests/testData/inspection/dataFlow/contractCheck/DoubleParameter.java
new file mode 100644 (file)
index 0000000..d88bbcc
--- /dev/null
@@ -0,0 +1,11 @@
+import org.jetbrains.annotations.Contract;
+
+class Zoo {
+  @Contract("null, _ -> null; !null, _ -> !null")
+  public static Double testContract_1(Double value1, int value2) {
+    if (value1 == null) {
+      return null;
+    }
+    return 0.0;
+  }
+}
\ No newline at end of file
index 50355f3c9ced5321570080fd66cb043e8afebd8f..eb1cc994138dc8016777106d5024d44f47c70ef9 100644 (file)
@@ -41,4 +41,5 @@ public class ContractCheckTest extends LightCodeInsightFixtureTestCase {
 
   public void testSignatureIssues() { doTest(); }
   public void testVarargInferred() { doTest(); }
+  public void testDoubleParameter() { doTest(); }
 }