Merge pull request #795 from mcgee/KT-10124

#KT-10124 Fixed
This commit is contained in:
Dmitry Jemerov
2015-12-09 15:28:31 +01:00
5 changed files with 78 additions and 37 deletions
@@ -1573,7 +1573,7 @@ public class KotlinParsing extends AbstractKotlinParsing {
private void parseFunctionOrPropertyName(boolean receiverFound, String title, TokenSet nameFollow, boolean nameRequired) { private void parseFunctionOrPropertyName(boolean receiverFound, String title, TokenSet nameFollow, boolean nameRequired) {
if (nameRequired && atSet(nameFollow)) return; // no name 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) { if (!receiverFound) {
expect(IDENTIFIER, "Expecting " + title + " name or receiver type", recoverySet); expect(IDENTIFIER, "Expecting " + title + " name or receiver type", recoverySet);
} }
@@ -294,46 +294,54 @@ JetFile: FunctionsWithFunctionReceiversRecovery.kt
PsiWhiteSpace('\n') PsiWhiteSpace('\n')
FUN FUN
PsiElement(fun)('fun') PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiErrorElement:Expecting function name or receiver type PsiErrorElement:Expecting function name or receiver type
PsiElement(fun)('fun')
PsiErrorElement:Expecting '('
<empty list> <empty list>
PsiWhiteSpace(' ') PsiWhiteSpace(' ')
MODIFIER_LIST FUN
ANNOTATION PsiElement(fun)('fun')
PsiElement(AT)('@') PsiWhiteSpace(' ')
PsiElement(LBRACKET)('[') TYPE_REFERENCE
ANNOTATION_ENTRY ANNOTATION
CONSTRUCTOR_CALLEE PsiElement(AT)('@')
TYPE_REFERENCE PsiElement(LBRACKET)('[')
USER_TYPE ANNOTATION_ENTRY
REFERENCE_EXPRESSION CONSTRUCTOR_CALLEE
PsiElement(IDENTIFIER)('a') TYPE_REFERENCE
PsiElement(RBRACKET)(']') USER_TYPE
PsiWhiteSpace(' ') REFERENCE_EXPRESSION
PsiErrorElement:Expecting a top level declaration PsiElement(IDENTIFIER)('a')
PsiElement(IDENTIFIER)('T') PsiElement(RBRACKET)(']')
PsiErrorElement:Expecting a top level declaration PsiWhiteSpace(' ')
PsiElement(LT)('<') USER_TYPE
PsiErrorElement:Expecting a top level declaration REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('T') PsiElement(IDENTIFIER)('T')
PsiErrorElement:Expecting a top level declaration TYPE_ARGUMENT_LIST
PsiElement(GT)('>') PsiElement(LT)('<')
PsiErrorElement:Expecting a top level declaration TYPE_PROJECTION
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('T')
PsiElement(GT)('>')
PsiElement(DOT)('.') PsiElement(DOT)('.')
PsiErrorElement:Expecting a top level declaration VALUE_PARAMETER_LIST
PsiElement(LPAR)('(') PsiElement(LPAR)('(')
PsiErrorElement:Expecting a top level declaration VALUE_PARAMETER
PsiElement(IDENTIFIER)('A') PsiErrorElement:Parameter name expected
PsiErrorElement:Expecting a top level declaration <empty list>
PsiElement(LT)('<') TYPE_REFERENCE
PsiErrorElement:Expecting a top level declaration USER_TYPE
PsiElement(IDENTIFIER)('B') REFERENCE_EXPRESSION
PsiErrorElement:Expecting a top level declaration PsiElement(IDENTIFIER)('A')
PsiElement(GT)('>') TYPE_ARGUMENT_LIST
PsiErrorElement:Expecting a top level declaration PsiElement(LT)('<')
PsiElement(RPAR)(')') TYPE_PROJECTION
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('B')
PsiElement(GT)('>')
PsiElement(RPAR)(')')
PsiErrorElement:Expecting a top level declaration PsiErrorElement:Expecting a top level declaration
PsiElement(DOT)('.') PsiElement(DOT)('.')
PsiErrorElement:Expecting a top level declaration PsiErrorElement:Expecting a top level declaration
+5
View File
@@ -0,0 +1,5 @@
fun
fun foo() {
}
+22
View File
@@ -0,0 +1,22 @@
JetFile: FunFun.kt
PACKAGE_DIRECTIVE
<empty list>
IMPORT_LIST
<empty list>
FUN
PsiElement(fun)('fun')
PsiErrorElement:Expecting function name or receiver type
<empty list>
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)('}')
@@ -2046,6 +2046,12 @@ public class ParsingTestGenerated extends AbstractParsingTest {
doParsingTest(fileName); 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") @TestMetadata("IfKeywordRBrace.kt")
public void testIfKeywordRBrace() throws Exception { public void testIfKeywordRBrace() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/psi/recovery/IfKeywordRBrace.kt"); String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/psi/recovery/IfKeywordRBrace.kt");