lambda: break/continue inside lambda body checks

(cherry picked from commit a290c356e646bb8ad9c097664648ad9033adf2a8)
This commit is contained in:
anna
2013-11-25 16:48:04 +01:00
parent f8e74f085c
commit d338bc76df
6 changed files with 84 additions and 4 deletions
@@ -30,7 +30,7 @@ public class EnclosingLoopMatcherExpression implements PsiMatcherExpression {
if (element instanceof PsiForeachStatement) return Boolean.TRUE;
if (element instanceof PsiWhileStatement) return Boolean.TRUE;
if (element instanceof PsiDoWhileStatement) return Boolean.TRUE;
if (element instanceof PsiMethod || element instanceof PsiClassInitializer) return null;
if (element instanceof PsiMethod || element instanceof PsiClassInitializer || element instanceof PsiLambdaExpression) return null;
return Boolean.FALSE;
}
}
@@ -31,7 +31,7 @@ public class EnclosingLoopOrSwitchMatcherExpression implements PsiMatcherExpress
if (element instanceof PsiWhileStatement) return Boolean.TRUE;
if (element instanceof PsiDoWhileStatement) return Boolean.TRUE;
if (element instanceof PsiSwitchStatement) return Boolean.TRUE;
if (element instanceof PsiMethod || element instanceof PsiClassInitializer) return null;
if (element instanceof PsiMethod || element instanceof PsiClassInitializer || element instanceof PsiLambdaExpression) return null;
return Boolean.FALSE;
}
}
@@ -65,7 +65,7 @@ public class PsiBreakStatementImpl extends CompositePsiElement implements PsiBre
}
}
if (parent.getElementType() == METHOD || parent.getElementType() == CLASS_INITIALIZER) return null; // do not pass through anonymous/local class
if (parent.getElementType() == METHOD || parent.getElementType() == CLASS_INITIALIZER || parent.getElementType() == LAMBDA_EXPRESSION) return null; // do not pass through anonymous/local class
}
}
return null;
@@ -61,7 +61,7 @@ public class PsiContinueStatementImpl extends CompositePsiElement implements Psi
return ((PsiLabeledStatement)SourceTreeToPsiMap.treeElementToPsi(parent)).getStatement();
}
}
if (parent.getElementType() == METHOD || parent.getElementType() == CLASS_INITIALIZER) return null; // do not pass through anonymous/local class
if (parent.getElementType() == METHOD || parent.getElementType() == CLASS_INITIALIZER || parent.getElementType() == LAMBDA_EXPRESSION) return null; // do not pass through anonymous/local class
}
}
return null;
@@ -0,0 +1,79 @@
class Test {
static interface I {
void m();
}
I i1 = ()-> { continue <error descr="Undefined label: 'l'">l</error>; };
I i2 = ()-> { break <error descr="Undefined label: 'l'">l</error>; };
I i3 = ()-> {
I i_i1 = ()-> { continue <error descr="Undefined label: 'l'">l</error>; };
I i_i2= ()-> { break <error descr="Undefined label: 'l'">l</error>; };
foo:
while (true) {
if (false) {
break;
}
if (true) {
break <error descr="Undefined label: 'l'">l</error>;
} else {
continue foo;
}
if (false) {
break <error descr="Undefined label: 'l1'">l1</error>;
}
}
};
I i4 = ()-> { <error descr="Continue outside of loop">continue;</error> };
I i5 = ()-> { <error descr="Break outside switch or loop">break;</error> };
{
l:
while (true) {
I i1 = ()-> { continue <error descr="Undefined label: 'l'">l</error>; };
I i2 = ()-> { break <error descr="Undefined label: 'l'">l</error>; };
I i3 = ()-> {
I i_i1 = ()-> { continue <error descr="Undefined label: 'l'">l</error>; };
I i_i2= ()-> { break <error descr="Undefined label: 'l'">l</error>; };
foo:
while (true) {
if (false) {
break;
}
if (true) {
break <error descr="Undefined label: 'l'">l</error>;
} else {
continue foo;
}
if (false) {
break <error descr="Undefined label: 'l1'">l1</error>;
}
}
};
}
while (true) {
I i1 = ()-> { continue <error descr="Undefined label: 'l'">l</error>; };
I i2 = ()-> { break <error descr="Undefined label: 'l'">l</error>; };
I i3 = ()-> {
I i_i1 = ()-> { continue <error descr="Undefined label: 'l'">l</error>; };
I i_i2= ()-> { break <error descr="Undefined label: 'l'">l</error>; };
foo:
while (true) {
if (false) {
break;
}
if (true) {
break <error descr="Undefined label: 'l'">l</error>;
} else {
continue foo;
}
if (false) {
break <error descr="Undefined label: 'l1'">l1</error>;
}
}
};
}
}
}
@@ -94,6 +94,7 @@ public class LambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testReturnTypeAmbiguity() { doTest();}
public void testWildcardsAndFormalLambdaParams() {doTest();}
public void testFinalInitializer() {doTest();}
public void testBreakContinueInside() {doTest();}
private void doTest() {
doTest(false);