Don't parse entries if left brace absent in 'when'

This commit is contained in:
Nikolay Krasko
2014-06-24 14:48:02 +04:00
parent f36f1796d6
commit d8490ce2a6
5 changed files with 43 additions and 6 deletions
@@ -780,13 +780,13 @@ public class JetExpressionParsing extends AbstractJetParsing {
// Parse when block
myBuilder.enableNewlines();
expect(LBRACE, "Expecting '{'");
if (expect(LBRACE, "Expecting '{'")) {
while (!eof() && !at(RBRACE)) {
parseWhenEntry();
}
while (!eof() && !at(RBRACE)) {
parseWhenEntry();
expect(RBRACE, "Expecting '}'");
}
expect(RBRACE, "Expecting '}'");
myBuilder.restoreNewlinesState();
when.done(WHEN);
@@ -1,3 +1,3 @@
fun test(a: Any) {
when (a)<!SYNTAX!><!>
}<!SYNTAX!><!>
}
@@ -0,0 +1,5 @@
fun test() {
when
bar()
}
@@ -0,0 +1,27 @@
JetFile: WhenWithoutBraces.kt
PACKAGE_DIRECTIVE
<empty list>
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('test')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
BLOCK
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
WHEN
PsiElement(when)('when')
PsiErrorElement:Expecting '{'
<empty list>
PsiWhiteSpace('\n\n ')
CALL_EXPRESSION
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('bar')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
@@ -1015,6 +1015,11 @@ public class JetParsingTestGenerated extends AbstractJetParsingTest {
doParsingTest("compiler/testData/psi/recovery/ValueParameterNoTypeRecovery.kt");
}
@TestMetadata("WhenWithoutBraces.kt")
public void testWhenWithoutBraces() throws Exception {
doParsingTest("compiler/testData/psi/recovery/WhenWithoutBraces.kt");
}
@TestMetadata("WhileWithEmptyCondition.kt")
public void testWhileWithEmptyCondition() throws Exception {
doParsingTest("compiler/testData/psi/recovery/WhileWithEmptyCondition.kt");