diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java index 2373777862e..1c6dbfb32d7 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java @@ -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); diff --git a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteWhen.kt b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteWhen.kt index d76fd7427d0..e169c711d74 100644 --- a/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteWhen.kt +++ b/compiler/testData/diagnostics/tests/incompleteCode/diagnosticWithSyntaxError/incompleteWhen.kt @@ -1,3 +1,3 @@ fun test(a: Any) { when (a) -} \ No newline at end of file +} \ No newline at end of file diff --git a/compiler/testData/psi/recovery/WhenWithoutBraces.kt b/compiler/testData/psi/recovery/WhenWithoutBraces.kt new file mode 100644 index 00000000000..02fa66a9393 --- /dev/null +++ b/compiler/testData/psi/recovery/WhenWithoutBraces.kt @@ -0,0 +1,5 @@ +fun test() { + when + + bar() +} \ No newline at end of file diff --git a/compiler/testData/psi/recovery/WhenWithoutBraces.txt b/compiler/testData/psi/recovery/WhenWithoutBraces.txt new file mode 100644 index 00000000000..c6f02f30cfa --- /dev/null +++ b/compiler/testData/psi/recovery/WhenWithoutBraces.txt @@ -0,0 +1,27 @@ +JetFile: WhenWithoutBraces.kt + PACKAGE_DIRECTIVE + + 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 '{' + + PsiWhiteSpace('\n\n ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('bar') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/parsing/JetParsingTestGenerated.java b/compiler/tests/org/jetbrains/jet/parsing/JetParsingTestGenerated.java index bc669636385..17336c86494 100644 --- a/compiler/tests/org/jetbrains/jet/parsing/JetParsingTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/parsing/JetParsingTestGenerated.java @@ -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");