diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java index f2b009b8d62..e14ec5a3e90 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java @@ -624,19 +624,21 @@ public class JetParsing extends AbstractJetParsing { * : ("{" memberDeclaration* "}")? * ; */ - /*package*/ void parseClassBody() { + private void parseClassBody() { PsiBuilder.Marker body = mark(); myBuilder.enableNewlines(); - expect(LBRACE, "Expecting a class body", TokenSet.create(LBRACE)); - while (!eof()) { - if (at(RBRACE)) { - break; + if (expect(LBRACE, "Expecting a class body")) { + while (!eof()) { + if (at(RBRACE)) { + break; + } + parseMemberDeclaration(); } - parseMemberDeclaration(); + expect(RBRACE, "Missing '}"); } - expect(RBRACE, "Missing '}"); + myBuilder.restoreNewlinesState(); body.done(CLASS_BODY); diff --git a/compiler/testData/psi/recovery/kt5102.kt b/compiler/testData/psi/recovery/kt5102.kt new file mode 100644 index 00000000000..75bbd25c680 --- /dev/null +++ b/compiler/testData/psi/recovery/kt5102.kt @@ -0,0 +1,8 @@ +fun foo() { + bar() // unresolved + + return object : Foo +} + +fun bar() {} + diff --git a/compiler/testData/psi/recovery/kt5102.txt b/compiler/testData/psi/recovery/kt5102.txt new file mode 100644 index 00000000000..dd729af3a1e --- /dev/null +++ b/compiler/testData/psi/recovery/kt5102.txt @@ -0,0 +1,55 @@ +JetFile: kt5102.kt + PACKAGE_DIRECTIVE + + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('bar') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiComment(EOL_COMMENT)('// unresolved') + PsiWhiteSpace('\n\n ') + RETURN + PsiElement(return)('return') + PsiWhiteSpace(' ') + OBJECT_LITERAL + OBJECT_DECLARATION + PsiElement(object)('object') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + DELEGATION_SPECIFIER_LIST + DELEGATOR_SUPER_CLASS + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Foo') + PsiWhiteSpace('\n') + CLASS_BODY + PsiErrorElement:Expecting a class body + + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('bar') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + 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 a816c56137e..b170b9bcb3c 100644 --- a/compiler/tests/org/jetbrains/jet/parsing/JetParsingTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/parsing/JetParsingTestGenerated.java @@ -900,6 +900,11 @@ public class JetParsingTestGenerated extends AbstractJetParsingTest { doParsingTest("compiler/testData/psi/recovery/kt2172.kt"); } + @TestMetadata("kt5102.kt") + public void testKt5102() throws Exception { + doParsingTest("compiler/testData/psi/recovery/kt5102.kt"); + } + @TestMetadata("MissingCommaInConstructorValueParameterList.kt") public void testMissingCommaInConstructorValueParameterList() throws Exception { doParsingTest("compiler/testData/psi/recovery/MissingCommaInConstructorValueParameterList.kt");