report 'break' and 'continue' inside 'when' as errors (even if 'when' is nested in a loop)
This commit is contained in:
committed by
Andrey Breslav
parent
8ab12e217d
commit
252c4118eb
@@ -977,6 +977,12 @@ public class JetControlFlowProcessor {
|
||||
loop = builder.getCurrentLoop();
|
||||
if (loop == null) {
|
||||
trace.report(BREAK_OR_CONTINUE_OUTSIDE_A_LOOP.on(expression));
|
||||
} else {
|
||||
JetWhenExpression whenExpression = PsiTreeUtil.getParentOfType(expression, JetWhenExpression.class, true,
|
||||
JetLoopExpression.class);
|
||||
if (whenExpression != null) {
|
||||
trace.report(BREAK_OR_CONTINUE_IN_WHEN.on(expression));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (loop != null && loop.getBody() != null
|
||||
|
||||
@@ -500,6 +500,7 @@ public interface Errors {
|
||||
DiagnosticFactory0<JetSimpleNameExpression> AMBIGUOUS_LABEL = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<JetExpressionWithLabel> BREAK_OR_CONTINUE_OUTSIDE_A_LOOP = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<JetExpressionWithLabel> BREAK_OR_CONTINUE_IN_WHEN = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<JetExpressionWithLabel> BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory1<JetExpressionWithLabel, String> NOT_A_LOOP_LABEL = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<JetReturnExpression, String> NOT_A_RETURN_LABEL = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
+1
@@ -407,6 +407,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(NO_TAIL_CALLS_FOUND, "A function is marked as tail-recursive but no tail calls are found");
|
||||
MAP.put(VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION, "A type annotation is required on a value parameter");
|
||||
MAP.put(BREAK_OR_CONTINUE_OUTSIDE_A_LOOP, "'break' and 'continue' are only allowed inside a loop");
|
||||
MAP.put(BREAK_OR_CONTINUE_IN_WHEN, "'break' and 'continue' are not allowed in 'when' statements. Consider using labels to continue/break from the outer loop");
|
||||
MAP.put(BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY, "'break' or 'continue' jumps across a function boundary");
|
||||
MAP.put(NOT_A_LOOP_LABEL, "The label ''{0}'' does not denote a loop", STRING);
|
||||
MAP.put(NOT_A_RETURN_LABEL, "The label ''{0}'' does not reference to a context from which we can return", STRING);
|
||||
|
||||
Reference in New Issue
Block a user