diff --git a/compiler/frontend/src/org/jetbrains/kotlin/parsing/AbstractJetParsing.java b/compiler/frontend/src/org/jetbrains/kotlin/parsing/AbstractJetParsing.java index 02c6a62202d..8c19df8653b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/parsing/AbstractJetParsing.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/parsing/AbstractJetParsing.java @@ -83,6 +83,10 @@ import static org.jetbrains.kotlin.lexer.JetTokens.*; return true; } + if (expectation == JetTokens.IDENTIFIER && "`".equals(myBuilder.getTokenText())) { + advance(); + } + errorWithRecovery(message, recoverySet); return false; diff --git a/compiler/testData/psi/EmptyName.kt b/compiler/testData/psi/EmptyName.kt new file mode 100644 index 00000000000..82f19a4b0ef --- /dev/null +++ b/compiler/testData/psi/EmptyName.kt @@ -0,0 +1,14 @@ +val ``: Int = 1 + +fun ``() {} + +class `` {} + +fun <``> f() {} + +class Data(val x: Int, val y: Int) +fun g() { + for (`` in 1..10) { + val (``, y) = Data(1, 2) + } +} \ No newline at end of file diff --git a/compiler/testData/psi/EmptyName.txt b/compiler/testData/psi/EmptyName.txt new file mode 100644 index 00000000000..e8ae2165a8f --- /dev/null +++ b/compiler/testData/psi/EmptyName.txt @@ -0,0 +1,169 @@ +JetFile: EmptyName.kt + PACKAGE_DIRECTIVE + + IMPORT_LIST + + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(BAD_CHARACTER)('`') + PsiErrorElement:Expecting property name or receiver type + PsiElement(BAD_CHARACTER)('`') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiWhiteSpace('\n\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(BAD_CHARACTER)('`') + PsiErrorElement:Expecting function name or receiver type + PsiElement(BAD_CHARACTER)('`') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + CLASS + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(BAD_CHARACTER)('`') + PsiErrorElement:Name expected + PsiElement(BAD_CHARACTER)('`') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + TYPE_PARAMETER_LIST + PsiElement(LT)('<') + TYPE_PARAMETER + PsiElement(BAD_CHARACTER)('`') + PsiErrorElement:Type parameter name expected + PsiElement(BAD_CHARACTER)('`') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('f') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + CLASS + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('Data') + PRIMARY_CONSTRUCTOR + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('x') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_PARAMETER + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('y') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('g') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + FOR + PsiElement(for)('for') + PsiWhiteSpace(' ') + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(BAD_CHARACTER)('`') + PsiErrorElement:Expecting a variable name + PsiElement(BAD_CHARACTER)('`') + PsiWhiteSpace(' ') + PsiElement(in)('in') + PsiWhiteSpace(' ') + LOOP_RANGE + BINARY_EXPRESSION + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + OPERATION_REFERENCE + PsiElement(RANGE)('..') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('10') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BODY + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + MULTI_VARIABLE_DECLARATION + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(LPAR)('(') + MULTI_VARIABLE_DECLARATION_ENTRY + PsiElement(BAD_CHARACTER)('`') + PsiErrorElement:Expecting a name + PsiElement(BAD_CHARACTER)('`') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + MULTI_VARIABLE_DECLARATION_ENTRY + PsiElement(IDENTIFIER)('y') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Data') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('1') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_ARGUMENT + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('2') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n ') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/parsing/JetParsingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/parsing/JetParsingTestGenerated.java index 45445d58c26..53f570852d2 100644 --- a/compiler/tests/org/jetbrains/kotlin/parsing/JetParsingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/parsing/JetParsingTestGenerated.java @@ -205,6 +205,12 @@ public class JetParsingTestGenerated extends AbstractJetParsingTest { doParsingTest(fileName); } + @TestMetadata("EmptyName.kt") + public void testEmptyName() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/EmptyName.kt"); + doParsingTest(fileName); + } + @TestMetadata("EnumCommas.kt") public void testEnumCommas() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/EnumCommas.kt");