mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
can complete normally: break inside switch (IDEA-178304)
break inside switch when switch is selected should not lead to abnormal completion
This commit is contained in:
@@ -885,7 +885,7 @@ class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
if (((PsiSwitchLabelStatement)aStatement).isDefaultCase()) {
|
||||
defaultLabel = (PsiSwitchLabelStatement)aStatement;
|
||||
}
|
||||
Instruction instruction = new ConditionalGoToInstruction(0, statement.getExpression());
|
||||
Instruction instruction = new ConditionalGoToInstruction(0, expr);
|
||||
myCurrentFlow.addInstruction(instruction);
|
||||
addElementOffsetLater(aStatement, true);
|
||||
}
|
||||
|
||||
@@ -1044,8 +1044,17 @@ public class ControlFlowUtil {
|
||||
boolean isNormal = nextOffset <= endOffset && !isReturn && (nextOffset == endOffset || canCompleteNormally[nextOffset]);
|
||||
if (isNormal && nextOffset == endOffset) {
|
||||
PsiElement element = flow.getElement(offset);
|
||||
if (element instanceof PsiBreakStatement || element instanceof PsiContinueStatement) {
|
||||
isNormal = false;
|
||||
if (element instanceof PsiBreakStatement) {
|
||||
PsiStatement exitedStatement = ((PsiBreakStatement)element).findExitedStatement();
|
||||
if (exitedStatement == null || flow.getStartOffset(exitedStatement) < startOffset) {
|
||||
isNormal = false;
|
||||
}
|
||||
}
|
||||
else if (element instanceof PsiContinueStatement) {
|
||||
PsiStatement continuedStatement = ((PsiContinueStatement)element).findContinuedStatement();
|
||||
if (continuedStatement == null || flow.getStartOffset(continuedStatement) < startOffset) {
|
||||
isNormal = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
canCompleteNormally[offset] |= isNormal;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
||||
class Test {
|
||||
private void m(ExecutorService service, int i) {
|
||||
service.submit(() -> {
|
||||
switch (i) {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -161,6 +161,7 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
public void testConditionalExpressionInLambdaReturns() { doTest(); }
|
||||
public void testLambdaWithFormalTypeParameters() { doTest(); }
|
||||
public void testIDEA174924() { doTest(); }
|
||||
public void testVoidValueCompatibilityWithBreakInSwitch() { doTest(); }
|
||||
|
||||
private void doTest() {
|
||||
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_8, getModule(), getTestRootDisposable());
|
||||
|
||||
Reference in New Issue
Block a user