DfaBinOpValue: fix for float/double casts (EA-221317); more tests

GitOrigin-RevId: d9dbe0360a9427cf601eebe0b585fbfc7c45ccd8
This commit is contained in:
Tagir Valeev
2020-01-30 04:13:49 +00:00
committed by intellij-monorepo-bot
parent 0627787d7c
commit c40db04b6c
2 changed files with 12 additions and 0 deletions
@@ -9,6 +9,7 @@ import com.intellij.psi.JavaTokenType;
import com.intellij.psi.PsiPrimitiveType;
import com.intellij.psi.PsiType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.TypeConversionUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -81,6 +82,7 @@ public class DfaBinOpValue extends DfaValue {
@NotNull
public DfaValue tryReduceOnCast(DfaMemoryState state, PsiPrimitiveType type) {
if (!TypeConversionUtil.isIntegralNumberType(type)) return this;
if ((myOp == BinOp.PLUS || myOp == BinOp.MINUS) &&
DfLongType.extractRange(state.getDfType(myRight)).castTo(type).equals(LongRangeSet.point(0))) {
return myLeft;
@@ -16,4 +16,14 @@ public class ReduceBinOpOnCast {
if (<warning descr="Condition 'res == b' is always 'true'">res == b</warning>) {}
}
}
void testTwoChecks(int a, short b) {
if (a == 0x10000 || a == 0x20000 || a == 0) {
<warning descr="Variable update does nothing">b</warning> += a;
}
}
void testDoubleCast(int x) {
double d = x + 1;
}
}