From 446941257b2b9d8d1f9adf4a925be18374387efc Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Thu, 9 Jan 2014 15:00:41 +0400 Subject: [PATCH] KT-4392 #Fixed --- .../jet/lang/parsing/JetParsing.java | 5 +- ...ingCommaInConstructorValueParameterList.kt | 3 + ...ngCommaInConstructorValueParameterList.txt | 79 +++++++++++++++++++ .../MissingCommaInValueParameterList.txt | 2 + .../jet/parsing/JetParsingTestGenerated.java | 5 ++ 5 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/psi/recovery/MissingCommaInConstructorValueParameterList.kt create mode 100644 compiler/testData/psi/recovery/MissingCommaInConstructorValueParameterList.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 f7a216c6412..2d877d66762 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java @@ -1712,7 +1712,10 @@ public class JetParsing extends AbstractJetParsing { if (at(COMMA)) { advance(); // COMMA } - else if (!atSet(VALUE_PARAMETER_FIRST)) break; + else { + if (!at(RPAR)) error("Expecting comma or ')'"); + if (!atSet(VALUE_PARAMETER_FIRST)) break; + } } } diff --git a/compiler/testData/psi/recovery/MissingCommaInConstructorValueParameterList.kt b/compiler/testData/psi/recovery/MissingCommaInConstructorValueParameterList.kt new file mode 100644 index 00000000000..41d861d0ce8 --- /dev/null +++ b/compiler/testData/psi/recovery/MissingCommaInConstructorValueParameterList.kt @@ -0,0 +1,3 @@ +class Test(private val a: Int b: Int private val c: Int) { + fun toString() = "$a $c" +} \ No newline at end of file diff --git a/compiler/testData/psi/recovery/MissingCommaInConstructorValueParameterList.txt b/compiler/testData/psi/recovery/MissingCommaInConstructorValueParameterList.txt new file mode 100644 index 00000000000..29f61aae63a --- /dev/null +++ b/compiler/testData/psi/recovery/MissingCommaInConstructorValueParameterList.txt @@ -0,0 +1,79 @@ +JetFile: MissingCommaInConstructorValueParameterList.kt + NAMESPACE_HEADER + + CLASS + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('Test') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + MODIFIER_LIST + PsiElement(private)('private') + PsiWhiteSpace(' ') + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('a') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiErrorElement:Expecting comma + + PsiWhiteSpace(' ') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('b') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiErrorElement:Expecting comma + + PsiWhiteSpace(' ') + VALUE_PARAMETER + MODIFIER_LIST + PsiElement(private)('private') + PsiWhiteSpace(' ') + 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 + 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)('c') + PsiElement(CLOSING_QUOTE)('"') + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/testData/psi/recovery/MissingCommaInValueParameterList.txt b/compiler/testData/psi/recovery/MissingCommaInValueParameterList.txt index 6d69387549b..d803521d3ea 100644 --- a/compiler/testData/psi/recovery/MissingCommaInValueParameterList.txt +++ b/compiler/testData/psi/recovery/MissingCommaInValueParameterList.txt @@ -26,6 +26,8 @@ JetFile: MissingCommaInValueParameterList.kt USER_TYPE REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('Int') + PsiErrorElement:Expecting comma + PsiWhiteSpace('\n ') VALUE_PARAMETER PsiElement(IDENTIFIER)('c') diff --git a/compiler/tests/org/jetbrains/jet/parsing/JetParsingTestGenerated.java b/compiler/tests/org/jetbrains/jet/parsing/JetParsingTestGenerated.java index e6b9cc4b113..b6aa9ffc11b 100644 --- a/compiler/tests/org/jetbrains/jet/parsing/JetParsingTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/parsing/JetParsingTestGenerated.java @@ -883,6 +883,11 @@ public class JetParsingTestGenerated extends AbstractJetParsingTest { doParsingTest("compiler/testData/psi/recovery/kt2172.kt"); } + @TestMetadata("MissingCommaInConstructorValueParameterList.kt") + public void testMissingCommaInConstructorValueParameterList() throws Exception { + doParsingTest("compiler/testData/psi/recovery/MissingCommaInConstructorValueParameterList.kt"); + } + @TestMetadata("MissingCommaInValueArgumentList.kt") public void testMissingCommaInValueArgumentList() throws Exception { doParsingTest("compiler/testData/psi/recovery/MissingCommaInValueArgumentList.kt");