mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-115330 Incorrect "condition is always false"
This commit is contained in:
+8
-1
@@ -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(); }
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user