Mark code like if(x > Double.NaN) as "always false"

Fixes part of IDEA-193102 x > Double.NaN comparison should be highlighted as always false
This commit is contained in:
Tagir Valeev
2018-06-04 11:24:57 +07:00
parent 6fffd5a4dd
commit d0d9cf8e6f
2 changed files with 9 additions and 4 deletions
@@ -441,10 +441,7 @@ public class DfaMemoryStateImpl implements DfaMemoryState {
private boolean isEffectivelyNaN(@NotNull DfaValue dfaValue) {
for (DfaValue eqClass : getEquivalentValues(dfaValue)) {
if (isNaN(eqClass)) return true;
}
return false;
return isNaN(dfaValue) || getEquivalentValues(dfaValue).stream().anyMatch(DfaMemoryStateImpl::isNaN);
}
List<EqClass> getEqClasses() {
@@ -1,4 +1,12 @@
public class DoubleNaN {
void testNanCmp(double x) {
if (<warning descr="Condition 'x > Double.NaN' is always 'false'">x > Double.NaN</warning>) {
return;
}
boolean cmp = x > Double.NaN; // this is always false, a warning is expected
System.out.println(x > Double.NaN); // this is always false, a warning is expected
}
void test() {
double x = Double.NaN;
double y = Double.NaN;