mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-13 21:55:01 +07:00
IDEA-125248 Incorrect simplify for float
This commit is contained in:
+2
-14
@@ -272,7 +272,8 @@ public class StandardInstructionVisitor extends InstructionVisitor {
|
||||
|
||||
if (methodType == MethodCallInstruction.MethodType.CAST) {
|
||||
if (qualifierValue instanceof DfaConstValue) {
|
||||
return factory.getConstFactory().createFromValue(castConstValue((DfaConstValue)qualifierValue), type, ((DfaConstValue)qualifierValue).getConstant());
|
||||
Object casted = TypeConversionUtil.computeCastTo(((DfaConstValue)qualifierValue).getValue(), type);
|
||||
return factory.getConstFactory().createFromValue(casted, type, ((DfaConstValue)qualifierValue).getConstant());
|
||||
}
|
||||
return qualifierValue;
|
||||
}
|
||||
@@ -283,19 +284,6 @@ public class StandardInstructionVisitor extends InstructionVisitor {
|
||||
return DfaUnknownValue.getInstance();
|
||||
}
|
||||
|
||||
private static Object castConstValue(DfaConstValue constValue) {
|
||||
Object o = constValue.getValue();
|
||||
if (o instanceof Double || o instanceof Float) {
|
||||
double dbVal = o instanceof Double ? ((Double)o).doubleValue() : ((Float)o).doubleValue();
|
||||
// 5.0f == 5
|
||||
if (Math.floor(dbVal) != dbVal) {
|
||||
return o;
|
||||
}
|
||||
}
|
||||
|
||||
return TypeConversionUtil.computeCastTo(o, PsiType.LONG);
|
||||
}
|
||||
|
||||
protected boolean checkNotNullable(DfaMemoryState state,
|
||||
DfaValue value, NullabilityProblem problem,
|
||||
PsiElement anchor) {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
class Fun {
|
||||
public static void main(String[] args) throws Exception {
|
||||
float f = 1f;
|
||||
int x = <warning descr="Condition 'f == 1f' is always 'true'">f == 1f</warning> ? 1 : 2;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -182,6 +182,7 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
|
||||
|
||||
public void testMethodCallFlushesField() { doTest(); }
|
||||
public void testUnknownFloatMayBeNaN() { doTest(); }
|
||||
public void testFloatEquality() { doTest(); }
|
||||
public void testLastConstantConditionInAnd() { doTest(); }
|
||||
|
||||
public void testTransientFinalField() { doTest(); }
|
||||
|
||||
Reference in New Issue
Block a user