diff --git a/compiler/psi/src/org/jetbrains/kotlin/parsing/AbstractKotlinParsing.java b/compiler/psi/src/org/jetbrains/kotlin/parsing/AbstractKotlinParsing.java index b262daab95c..0af6879e70c 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/parsing/AbstractKotlinParsing.java +++ b/compiler/psi/src/org/jetbrains/kotlin/parsing/AbstractKotlinParsing.java @@ -105,7 +105,7 @@ import static org.jetbrains.kotlin.lexer.KtTokens.*; IElementType tt = tt(); if (recoverySet == null || recoverySet.contains(tt) || - tt == LBRACE || tt == RBRACE || tt == LONG_TEMPLATE_ENTRY_END || + tt == LBRACE || tt == RBRACE || (recoverySet.contains(EOL_OR_SEMICOLON) && (eof() || tt == SEMICOLON || myBuilder.newlineBeforeCurrentToken()))) { error(message); } diff --git a/compiler/psi/src/org/jetbrains/kotlin/parsing/KotlinExpressionParsing.java b/compiler/psi/src/org/jetbrains/kotlin/parsing/KotlinExpressionParsing.java index 0cfccd158c5..c353d90ad1c 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/parsing/KotlinExpressionParsing.java +++ b/compiler/psi/src/org/jetbrains/kotlin/parsing/KotlinExpressionParsing.java @@ -682,7 +682,7 @@ public class KotlinExpressionParsing extends AbstractKotlinParsing { else if (!parseLiteralConstant()) { ok = false; // TODO: better recovery if FIRST(element) did not match - errorWithRecovery("Expecting an element", EXPRESSION_FOLLOW); + errorWithRecovery("Expecting an element", TokenSet.orSet(EXPRESSION_FOLLOW, TokenSet.create(LONG_TEMPLATE_ENTRY_END))); } return ok; diff --git a/compiler/testData/psi/stringTemplates/kt46455.kt b/compiler/testData/psi/stringTemplates/kt46455.kt new file mode 100644 index 00000000000..5ff01546f93 --- /dev/null +++ b/compiler/testData/psi/stringTemplates/kt46455.kt @@ -0,0 +1,6 @@ +// ISSUE: KT-46455 + +class A { + fun bar() = + x foo(*z) ?: "${z.joinToString()}" +} diff --git a/compiler/testData/psi/stringTemplates/kt46455.txt b/compiler/testData/psi/stringTemplates/kt46455.txt new file mode 100644 index 00000000000..3e90580362b --- /dev/null +++ b/compiler/testData/psi/stringTemplates/kt46455.txt @@ -0,0 +1,66 @@ +KtFile: kt46455.kt + PACKAGE_DIRECTIVE + + IMPORT_LIST + + PsiComment(EOL_COMMENT)('// ISSUE: KT-46455') + PsiWhiteSpace('\n\n') + CLASS + PsiElement(class)('class') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('A') + PsiWhiteSpace(' ') + CLASS_BODY + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('bar') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace('\n ') + BINARY_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(IDENTIFIER)('foo') + BINARY_EXPRESSION + PARENTHESIZED + PsiElement(LPAR)('(') + PsiErrorElement:Expecting an expression + + OPERATION_REFERENCE + PsiElement(MUL)('*') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('z') + PsiErrorElement:Expecting member declaration + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiErrorElement:Expecting member declaration + PsiElement(ELVIS)('?:') + PsiWhiteSpace(' ') + PsiErrorElement:Expecting member declaration + PsiElement(OPEN_QUOTE)('"') + PsiErrorElement:Expecting member declaration + PsiElement(LONG_TEMPLATE_ENTRY_START)('${') + PsiErrorElement:Expecting member declaration + PsiElement(IDENTIFIER)('z') + PsiErrorElement:Expecting member declaration + PsiElement(DOT)('.') + PsiErrorElement:Expecting member declaration + PsiElement(IDENTIFIER)('joinToString') + PsiErrorElement:Expecting member declaration + PsiElement(LPAR)('(') + PsiErrorElement:Expecting member declaration + PsiElement(RPAR)(')') + PsiErrorElement:Expecting member declaration + PsiElement(LONG_TEMPLATE_ENTRY_END)('}') + PsiErrorElement:Expecting member declaration + PsiElement(CLOSING_QUOTE)('"') + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/tests-gen/org/jetbrains/kotlin/parsing/ParsingTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/parsing/ParsingTestGenerated.java index 5010f30c5f6..12716f3ea44 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/parsing/ParsingTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/parsing/ParsingTestGenerated.java @@ -2787,6 +2787,11 @@ public class ParsingTestGenerated extends AbstractParsingTest { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/psi/stringTemplates"), Pattern.compile("^(.*)\\.kts?$"), null, true); } + @TestMetadata("kt46455.kt") + public void testKt46455() throws Exception { + runTest("compiler/testData/psi/stringTemplates/kt46455.kt"); + } + @TestMetadata("RawStringsWithManyQuotes.kt") public void testRawStringsWithManyQuotes() throws Exception { runTest("compiler/testData/psi/stringTemplates/RawStringsWithManyQuotes.kt");