IDEA-246334 Dataflow to here: filtering long variable with <= 0 yields no results.

GitOrigin-RevId: 80981136f8e8541d4c5b872ccf851de9e550aa72
This commit is contained in:
Tagir Valeev
2020-07-22 04:08:51 +00:00
committed by intellij-monorepo-bot
parent c1c03744ac
commit 5c63dd413a
4 changed files with 23 additions and 3 deletions
@@ -53,9 +53,10 @@ final class DfaBasedFilter {
private boolean allowed(@NotNull PsiElement element, boolean assertionsDisabled) {
if (myDfType instanceof DfConstantType && element instanceof PsiLiteralValue) {
Object constValue = ((DfConstantType<?>)myDfType).getValue();
DfConstantType<?> dfConstantType = (DfConstantType<?>)myDfType;
Object constValue = dfConstantType.getValue();
if (!(constValue instanceof PsiElement)) {
Object value = ((PsiLiteralValue)element).getValue();
Object value = TypeConversionUtil.computeCastTo(((PsiLiteralValue)element).getValue(), dfConstantType.getPsiType());
return Objects.equals(value, constValue);
}
}
@@ -87,7 +88,12 @@ final class DfaBasedFilter {
CommonDataflow.DataflowResult result = CommonDataflow.getDataflowResult(expression);
if (result == null) return DfTypes.TOP;
expression = PsiUtil.skipParenthesizedExprDown(expression);
return assertionsDisabled ? result.getDfTypeNoAssertions(expression) : result.getDfType(expression);
DfType type = assertionsDisabled ? result.getDfTypeNoAssertions(expression) : result.getDfType(expression);
if (myDfType instanceof DfLongType && type instanceof DfIntType) {
// Implicit widening conversion
return DfTypes.longRange(((DfIntType)type).getRange());
}
return type;
}
@Override
@@ -0,0 +1,6 @@
class Test {
public static void main(String[] args) {
double x = <flown1>0;
System.out.println(<caret>x);
}
}
@@ -0,0 +1,6 @@
class Test {
public static void main(String[] args) {
long x = <flown1>0;
System.out.println(<caret>x);
}
}
@@ -114,6 +114,8 @@ public class SliceBackwardTest extends SliceTestCase {
public void testFilterPropagateBoolean2() throws Exception { doTest("false");}
public void testFilterAssertionViolation() throws Exception { doTest("-1");}
public void testReturnParameter() throws Exception { doTest(); }
public void testFilterLongByInt() throws Exception { doTest("<=0"); }
public void testFilterDoubleByInt() throws Exception { doTest("0.0"); }
public void testStackFilterSimple() throws Exception {
doTest("null", "MainTest:test", "MainTest:foo", "MainTest:main");