IDEA-94181 Boolean truth inference

This commit is contained in:
peter
2012-11-09 13:36:01 +01:00
parent d6d0cc0753
commit 501bac130e
4 changed files with 28 additions and 6 deletions
@@ -1094,15 +1094,13 @@ class ControlFlowAnalyzer extends JavaElementVisitor {
PsiExpression operand = operands[i];
operand.accept(this);
generateBoxingUnboxingInstructionFor(operand, exprType);
PsiExpression nextOperand = i == operands.length - 1 ? null : operands[i + 1];
if (nextOperand != null) {
ConditionalGotoInstruction onFail = new ConditionalGotoInstruction(-1, true, operand);
branchToFail.add(onFail);
addInstruction(onFail);
}
ConditionalGotoInstruction onFail = new ConditionalGotoInstruction(-1, true, operand);
branchToFail.add(onFail);
addInstruction(onFail);
}
addInstruction(new PushInstruction(myFactory.getConstFactory().getTrue(), null));
GotoInstruction toSuccess = new GotoInstruction(-1);
addInstruction(toSuccess);
PushInstruction pushFalse = new PushInstruction(myFactory.getConstFactory().getFalse(), null);
@@ -0,0 +1,14 @@
class Fun {
private void parseDeclarator(Object builder, boolean isTuple) {
if (!isTuple) {
return;
}
else {
if (smth() && <warning descr="Condition 'isTuple' is always 'true' when reached">isTuple</warning>) {
System.out.println();
}
}
}
boolean smth() { return true; }
}
@@ -375,4 +375,13 @@
<problem_class>Constant conditions &amp; exceptions</problem_class>
<description>Unboxing of &lt;code&gt;i&lt;/code&gt; may produce &lt;code&gt;java.lang.NullPointerException&lt;/code&gt;.</description>
</problem>
<problem>
<file>Test.java</file>
<line>67</line>
<package>&lt;default&gt;</package>
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Constant conditions &amp; exceptions</problem_class>
<description>Condition &lt;code&gt;i&lt;/code&gt; is always &lt;code&gt;true&lt;/code&gt; when reached</description>
</problem>
</problems>
@@ -138,5 +138,6 @@ public class DataFlowInspectionFixtureTest extends JavaCodeInsightFixtureTestCas
public void testMethodCallFlushesField() { doTest(); }
public void testUnknownFloatMayBeNaN() { doTest(); }
public void testLastConstantConditionInAnd() { doTest(); }
}