diff --git a/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinParsing.java b/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinParsing.java index 5277fad8d2b..44a95f10b15 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinParsing.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinParsing.java @@ -1573,7 +1573,7 @@ public class KotlinParsing extends AbstractKotlinParsing { private void parseFunctionOrPropertyName(boolean receiverFound, String title, TokenSet nameFollow, boolean nameRequired) { if (nameRequired && atSet(nameFollow)) return; // no name - TokenSet recoverySet = TokenSet.orSet(nameFollow, TokenSet.create(LBRACE, RBRACE)); + TokenSet recoverySet = TokenSet.orSet(nameFollow, TokenSet.create(LBRACE, RBRACE), TOP_LEVEL_DECLARATION_FIRST); if (!receiverFound) { expect(IDENTIFIER, "Expecting " + title + " name or receiver type", recoverySet); } diff --git a/compiler/testData/psi/functionReceivers/FunctionsWithFunctionReceiversRecovery.txt b/compiler/testData/psi/functionReceivers/FunctionsWithFunctionReceiversRecovery.txt index f219d293b3f..d849012826b 100644 --- a/compiler/testData/psi/functionReceivers/FunctionsWithFunctionReceiversRecovery.txt +++ b/compiler/testData/psi/functionReceivers/FunctionsWithFunctionReceiversRecovery.txt @@ -294,46 +294,54 @@ JetFile: FunctionsWithFunctionReceiversRecovery.kt PsiWhiteSpace('\n') FUN PsiElement(fun)('fun') - PsiWhiteSpace(' ') PsiErrorElement:Expecting function name or receiver type - PsiElement(fun)('fun') - PsiErrorElement:Expecting '(' PsiWhiteSpace(' ') - MODIFIER_LIST - ANNOTATION - PsiElement(AT)('@') - PsiElement(LBRACKET)('[') - ANNOTATION_ENTRY - CONSTRUCTOR_CALLEE - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('a') - PsiElement(RBRACKET)(']') - PsiWhiteSpace(' ') - PsiErrorElement:Expecting a top level declaration - PsiElement(IDENTIFIER)('T') - PsiErrorElement:Expecting a top level declaration - PsiElement(LT)('<') - PsiErrorElement:Expecting a top level declaration - PsiElement(IDENTIFIER)('T') - PsiErrorElement:Expecting a top level declaration - PsiElement(GT)('>') - PsiErrorElement:Expecting a top level declaration + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + TYPE_REFERENCE + ANNOTATION + PsiElement(AT)('@') + PsiElement(LBRACKET)('[') + ANNOTATION_ENTRY + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('a') + PsiElement(RBRACKET)(']') + PsiWhiteSpace(' ') + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + TYPE_ARGUMENT_LIST + PsiElement(LT)('<') + TYPE_PROJECTION + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiElement(GT)('>') PsiElement(DOT)('.') - PsiErrorElement:Expecting a top level declaration - PsiElement(LPAR)('(') - PsiErrorElement:Expecting a top level declaration - PsiElement(IDENTIFIER)('A') - PsiErrorElement:Expecting a top level declaration - PsiElement(LT)('<') - PsiErrorElement:Expecting a top level declaration - PsiElement(IDENTIFIER)('B') - PsiErrorElement:Expecting a top level declaration - PsiElement(GT)('>') - PsiErrorElement:Expecting a top level declaration - PsiElement(RPAR)(')') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiErrorElement:Parameter name expected + + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('A') + TYPE_ARGUMENT_LIST + PsiElement(LT)('<') + TYPE_PROJECTION + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('B') + PsiElement(GT)('>') + PsiElement(RPAR)(')') PsiErrorElement:Expecting a top level declaration PsiElement(DOT)('.') PsiErrorElement:Expecting a top level declaration diff --git a/compiler/testData/psi/recovery/FunFun.kt b/compiler/testData/psi/recovery/FunFun.kt new file mode 100644 index 00000000000..f8aa2f9a68e --- /dev/null +++ b/compiler/testData/psi/recovery/FunFun.kt @@ -0,0 +1,5 @@ +fun + +fun foo() { + +} \ No newline at end of file diff --git a/compiler/testData/psi/recovery/FunFun.txt b/compiler/testData/psi/recovery/FunFun.txt new file mode 100644 index 00000000000..8a8a056d80e --- /dev/null +++ b/compiler/testData/psi/recovery/FunFun.txt @@ -0,0 +1,22 @@ +JetFile: FunFun.kt + PACKAGE_DIRECTIVE + + IMPORT_LIST + + FUN + PsiElement(fun)('fun') + PsiErrorElement:Expecting function name or receiver type + + PsiWhiteSpace('\n\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n\n') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/parsing/ParsingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/parsing/ParsingTestGenerated.java index 4baead2d7e9..03e80eae4d6 100644 --- a/compiler/tests/org/jetbrains/kotlin/parsing/ParsingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/parsing/ParsingTestGenerated.java @@ -2040,6 +2040,12 @@ public class ParsingTestGenerated extends AbstractParsingTest { doParsingTest(fileName); } + @TestMetadata("FunFun.kt") + public void testFunFun() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/psi/recovery/FunFun.kt"); + doParsingTest(fileName); + } + @TestMetadata("IfKeywordRBrace.kt") public void testIfKeywordRBrace() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/psi/recovery/IfKeywordRBrace.kt");