IDEA-182501 Unwrap 'if' generates unreachable code

This commit is contained in:
peter
2018-01-03 21:47:57 +01:00
parent e133d0ff51
commit 41d78cd086
4 changed files with 20 additions and 3 deletions
@@ -421,7 +421,7 @@ class ControlFlowAnalyzer extends JavaElementVisitor {
instruction = new ReturnInstruction(0, myStack, callInstruction);
}
else {
instruction = new GoToInstruction(0);
instruction = new GoToInstruction(0, BranchingInstruction.Role.END, PsiTreeUtil.isAncestor(exitedStatement, myCodeFragment, true));
}
myCurrentFlow.addInstruction(instruction);
// exited statement might be out of control flow analyzed
@@ -483,7 +483,7 @@ class ControlFlowAnalyzer extends JavaElementVisitor {
instruction = new ReturnInstruction(0, myStack, callInstruction);
}
else {
instruction = new GoToInstruction(0);
instruction = new GoToInstruction(0, BranchingInstruction.Role.END, PsiTreeUtil.isAncestor(body, myCodeFragment, true));
}
myCurrentFlow.addInstruction(instruction);
addElementOffsetLater(body, false);
@@ -0,0 +1,7 @@
// "Unwrap 'if' statement" "true"
class X {
void f(){
while (true) {
continue;//comment
}
}}
@@ -0,0 +1,10 @@
// "Unwrap 'if' statement" "true"
class X {
void f(){
while (true) {
if (tr<caret>ue) {
continue;//comment
}
System.out.println();
}
}}
@@ -7,5 +7,5 @@
6: COND_THROW_TO 8
7: GOTO [END] 11
8: WRITE e
9: GOTO [END] 11
9: GOTO [END] 11 RETURN
10: GOTO [END] 11