IDEA-115330 Incorrect "condition is always false"

This commit is contained in:
peter
2013-11-09 18:19:09 +01:00
parent 0b85cc182f
commit a54334794b
4 changed files with 25 additions and 2 deletions
@@ -31,6 +31,7 @@ import com.intellij.util.IncorrectOperationException;
import com.intellij.util.SmartList;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.Stack;
import com.siyeh.ig.numeric.UnnecessaryExplicitNumericCastInspection;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -1874,7 +1875,13 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
final PsiTypeElement typeElement = castExpression.getCastType();
if (typeElement != null && operand != null) {
addInstruction(new TypeCastInstruction(castExpression, operand, typeElement.getType()));
if (typeElement.getType() instanceof PsiPrimitiveType &&
UnnecessaryExplicitNumericCastInspection.isPrimitiveNumericCastNecessary(castExpression)) {
addInstruction(new PopInstruction());
pushUnknown();
} else {
addInstruction(new TypeCastInstruction(castExpression, operand, typeElement.getType()));
}
}
finishElement(castExpression);
}
@@ -0,0 +1,15 @@
public class BrokenAlignment {
private static void foo(long value) {
if (value == (byte)value) {
System.out.println("1");
} else if (value == (short)value) {
System.out.println("2");
} else if (value == (int)value) {
System.out.println("3");
} else {
System.out.println("4");
}
}
}
@@ -122,6 +122,7 @@ public class DataFlowInspectionTest extends LightCodeInsightFixtureTestCase {
}
public void testPreserveNullableOnUncheckedCast() throws Throwable { doTest(); }
public void testPrimitiveCastMayChangeValue() throws Throwable { doTest(); }
public void testPassingNullableIntoVararg() throws Throwable { doTest(); }
public void testEqualsImpliesNotNull() throws Throwable { doTest(); }
@@ -140,7 +140,7 @@ public class UnnecessaryExplicitNumericCastInspection extends BaseInspection {
}
}
static boolean isPrimitiveNumericCastNecessary(PsiTypeCastExpression expression) {
public static boolean isPrimitiveNumericCastNecessary(PsiTypeCastExpression expression) {
final PsiType castType = expression.getType();
if (castType == null) {
return true;