ControlFlowAnalyzer#acceptBinaryRightOperand: properly convert type for comparison

Fixes IDEA-200364 Checking equality between int and double confuses "Constant condition and exception" inspection
This commit is contained in:
Tagir Valeev
2018-10-12 10:12:22 +07:00
parent 898f9e2c9d
commit ed64e02bee
2 changed files with 9 additions and 1 deletions
@@ -1423,7 +1423,7 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
TypeConversionUtil.isNumericType(lType) &&
TypeConversionUtil.isNumericType(rType);
PsiType castType = comparingPrimitiveNumeric ? TypeConversionUtil.isFloatOrDoubleType(lType) ? PsiType.DOUBLE : PsiType.LONG : type;
PsiType castType = comparingPrimitiveNumeric ? TypeConversionUtil.unboxAndBalanceTypes(lType, rType) : type;
if (!comparingRef) {
generateBoxingUnboxingInstructionFor(lExpr,castType);
@@ -5,4 +5,12 @@ class WideningToDouble {
boolean trueValue = <warning descr="Condition 'x == y' is always 'true'">x == y</warning>; // ASSIGNMENT
System.out.println(trueValue); // prints "true"
}
void test() {
int y = 2;
if (<warning descr="Condition 'y == 2.1' is always 'false'">y == 2.1</warning>) {
System.out.println("true");
} else
System.out.println("false");
}
}