From c40db04b6c39cd540c1a203d081864053b3161ca Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Thu, 30 Jan 2020 10:37:26 +0700 Subject: [PATCH] DfaBinOpValue: fix for float/double casts (EA-221317); more tests GitOrigin-RevId: d9dbe0360a9427cf601eebe0b585fbfc7c45ccd8 --- .../codeInspection/dataFlow/value/DfaBinOpValue.java | 2 ++ .../inspection/dataFlow/fixture/ReduceBinOpOnCast.java | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaBinOpValue.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaBinOpValue.java index bbe5a9294aec..e8785239b6a0 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaBinOpValue.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/value/DfaBinOpValue.java @@ -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; diff --git a/java/java-tests/testData/inspection/dataFlow/fixture/ReduceBinOpOnCast.java b/java/java-tests/testData/inspection/dataFlow/fixture/ReduceBinOpOnCast.java index ef86e5db9e9f..2312785c76a0 100644 --- a/java/java-tests/testData/inspection/dataFlow/fixture/ReduceBinOpOnCast.java +++ b/java/java-tests/testData/inspection/dataFlow/fixture/ReduceBinOpOnCast.java @@ -16,4 +16,14 @@ public class ReduceBinOpOnCast { if (res == b) {} } } + + void testTwoChecks(int a, short b) { + if (a == 0x10000 || a == 0x20000 || a == 0) { + b += a; + } + } + + void testDoubleCast(int x) { + double d = x + 1; + } }