JET-40 Check that 'else' entry is the last one in the list of 'when' entries
This commit is contained in:
@@ -622,11 +622,18 @@ public class JetControlFlowProcessor {
|
||||
Label doneLabel = builder.createUnboundLabel();
|
||||
|
||||
Label nextLabel = builder.createUnboundLabel();
|
||||
for (JetWhenEntry whenEntry : expression.getEntries()) {
|
||||
for (Iterator<JetWhenEntry> iterator = expression.getEntries().iterator(); iterator.hasNext(); ) {
|
||||
JetWhenEntry whenEntry = iterator.next();
|
||||
if (whenEntry.getSubWhen() != null) throw new UnsupportedOperationException(); // TODO
|
||||
|
||||
if (whenEntry.isElseContinue()) throw new UnsupportedOperationException(); // TODO
|
||||
|
||||
if (whenEntry.isElse()) {
|
||||
if (iterator.hasNext()) {
|
||||
trace.getErrorHandler().genericError(whenEntry.getNode(), "'else' entry must be the last one in a when-expression");
|
||||
}
|
||||
}
|
||||
|
||||
JetWhenCondition condition = whenEntry.getCondition();
|
||||
if (condition != null) {
|
||||
condition.accept(new JetVisitor() {
|
||||
|
||||
@@ -14,6 +14,7 @@ fun foo() {
|
||||
.<error>a</error> => 1
|
||||
.equals(1).<error>a</error> => 1
|
||||
<warning>?.</warning>equals(1) => 1
|
||||
else => 1
|
||||
}
|
||||
when (<warning>x</warning>?:null) {
|
||||
<error>.</error>equals(1) => 1
|
||||
@@ -46,6 +47,15 @@ fun test() {
|
||||
is boo @ (1, <error>"a"</error>, *) => 1
|
||||
is boo @ <error>(1, *)</error> => 1
|
||||
}
|
||||
|
||||
when (z) {
|
||||
<error>else => 1</error>
|
||||
(1, 1) => 2
|
||||
}
|
||||
|
||||
when (z) {
|
||||
else => 1
|
||||
}
|
||||
}
|
||||
|
||||
val (Int, Int).boo : (Int, Int, Int) = (1, 1, 1)
|
||||
|
||||
Reference in New Issue
Block a user