From 5d4527d7aae1c792f38577b380eec00df6cd3932 Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Mon, 24 Mar 2014 18:21:34 +0400 Subject: [PATCH] Parser: Fix recovery of constructor parameter list #KT-4739 Fixed --- .../jet/lang/parsing/JetParsing.java | 3 +- ...ngCommaInValueParameterListWithValOrVar.kt | 7 + ...gCommaInValueParameterListWithValOrVar.txt | 133 ++++++++++++++++++ .../jet/parsing/JetParsingTestGenerated.java | 5 + 4 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/psi/recovery/MissingCommaInValueParameterListWithValOrVar.kt create mode 100644 compiler/testData/psi/recovery/MissingCommaInValueParameterListWithValOrVar.txt 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 cd2722763c2..99dbf27efa0 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java @@ -50,7 +50,8 @@ public class JetParsing extends AbstractJetParsing { private static final TokenSet IMPORT_RECOVERY_SET = TokenSet.create(AS_KEYWORD, DOT, EOL_OR_SEMICOLON); /*package*/ static final TokenSet TYPE_REF_FIRST = TokenSet.create(LBRACKET, IDENTIFIER, FUN_KEYWORD, LPAR, CAPITALIZED_THIS_KEYWORD, HASH); private static final TokenSet RECEIVER_TYPE_TERMINATORS = TokenSet.create(DOT, SAFE_ACCESS); - private static final TokenSet VALUE_PARAMETER_FIRST = TokenSet.orSet(TokenSet.create(IDENTIFIER, LBRACKET), MODIFIER_KEYWORDS); + private static final TokenSet VALUE_PARAMETER_FIRST = + TokenSet.orSet(TokenSet.create(IDENTIFIER, LBRACKET, VAL_KEYWORD, VAR_KEYWORD), MODIFIER_KEYWORDS); static JetParsing createForTopLevel(SemanticWhitespaceAwarePsiBuilder builder) { JetParsing jetParsing = new JetParsing(builder); diff --git a/compiler/testData/psi/recovery/MissingCommaInValueParameterListWithValOrVar.kt b/compiler/testData/psi/recovery/MissingCommaInValueParameterListWithValOrVar.kt new file mode 100644 index 00000000000..727ca8cb4c5 --- /dev/null +++ b/compiler/testData/psi/recovery/MissingCommaInValueParameterListWithValOrVar.kt @@ -0,0 +1,7 @@ +class Test(val a: Int var b: Int val c: Int) { + override fun toString() = "$a $b $c" +} + +fun test(val a: Int var b: Int val c: Int) { + +} \ No newline at end of file diff --git a/compiler/testData/psi/recovery/MissingCommaInValueParameterListWithValOrVar.txt b/compiler/testData/psi/recovery/MissingCommaInValueParameterListWithValOrVar.txt new file mode 100644 index 00000000000..b08e7eb15f0 --- /dev/null +++ b/compiler/testData/psi/recovery/MissingCommaInValueParameterListWithValOrVar.txt @@ -0,0 +1,133 @@ +JetFile: MissingCommaInValueParameterListWithValOrVar.kt + PACKAGE_DIRECTIVE + + CLASS + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('Test') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('a') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiErrorElement:Expecting comma or ')' + + PsiWhiteSpace(' ') + VALUE_PARAMETER + PsiElement(var)('var') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('b') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiErrorElement:Expecting comma or ')' + + PsiWhiteSpace(' ') + VALUE_PARAMETER + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('c') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + FUN + MODIFIER_LIST + PsiElement(override)('override') + PsiWhiteSpace(' ') + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('toString') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + STRING_TEMPLATE + PsiElement(OPEN_QUOTE)('"') + SHORT_STRING_TEMPLATE_ENTRY + PsiElement(SHORT_TEMPLATE_ENTRY_START)('$') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('a') + LITERAL_STRING_TEMPLATE_ENTRY + PsiElement(REGULAR_STRING_PART)(' ') + SHORT_STRING_TEMPLATE_ENTRY + PsiElement(SHORT_TEMPLATE_ENTRY_START)('$') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('b') + LITERAL_STRING_TEMPLATE_ENTRY + PsiElement(REGULAR_STRING_PART)(' ') + SHORT_STRING_TEMPLATE_ENTRY + PsiElement(SHORT_TEMPLATE_ENTRY_START)('$') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('c') + PsiElement(CLOSING_QUOTE)('"') + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('test') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('a') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiErrorElement:Expecting comma or ')' + + PsiWhiteSpace(' ') + VALUE_PARAMETER + PsiElement(var)('var') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('b') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiErrorElement:Expecting comma or ')' + + PsiWhiteSpace(' ') + VALUE_PARAMETER + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('c') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n\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 73ec7b30e0b..9449eac1482 100644 --- a/compiler/tests/org/jetbrains/jet/parsing/JetParsingTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/parsing/JetParsingTestGenerated.java @@ -908,6 +908,11 @@ public class JetParsingTestGenerated extends AbstractJetParsingTest { doParsingTest("compiler/testData/psi/recovery/MissingCommaInValueParameterList.kt"); } + @TestMetadata("MissingCommaInValueParameterListWithValOrVar.kt") + public void testMissingCommaInValueParameterListWithValOrVar() throws Exception { + doParsingTest("compiler/testData/psi/recovery/MissingCommaInValueParameterListWithValOrVar.kt"); + } + @TestMetadata("PackageNewLineRecovery.kt") public void testPackageNewLineRecovery() throws Exception { doParsingTest("compiler/testData/psi/recovery/PackageNewLineRecovery.kt");