From 304c826b475ce99827a9b92da624fd422bea01bf Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Fri, 24 Oct 2014 00:36:14 +0400 Subject: [PATCH] Fixed KT-6128 Code completion does not work inside function literal if it's dependant on declarations below #KT-6128 Fixed --- .../lang/parsing/JetExpressionParsing.java | 2 +- compiler/testData/psi/FunctionLiterals.txt | 6 +- .../testData/psi/FunctionLiterals_ERR.txt | 308 +++++------ .../greatSyntacticShift/functionLiterals.txt | 505 +++++++++--------- .../recovery/InvalidCharInSingleLineLambda.kt | 7 + .../InvalidCharInSingleLineLambda.txt | 62 +++ .../recovery/SameLineStatementRecovery.txt | 21 +- .../jet/parsing/JetParsingTestGenerated.java | 6 + .../basic/common/InFunctionLiteral.kt | 9 + .../JSBasicCompletionTestGenerated.java | 6 + .../JvmBasicCompletionTestGenerated.java | 6 + 11 files changed, 516 insertions(+), 422 deletions(-) create mode 100644 compiler/testData/psi/recovery/InvalidCharInSingleLineLambda.kt create mode 100644 compiler/testData/psi/recovery/InvalidCharInSingleLineLambda.txt create mode 100644 idea/testData/completion/basic/common/InFunctionLiteral.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java index caeb877a32a..0a35e73ca30 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java @@ -1250,7 +1250,7 @@ public class JetExpressionParsing extends AbstractJetParsing { error(severalStatementsError); } else { - errorUntil(severalStatementsError, TokenSet.create(EOL_OR_SEMICOLON)); + errorUntil(severalStatementsError, TokenSet.create(EOL_OR_SEMICOLON, LBRACE, RBRACE)); } } } diff --git a/compiler/testData/psi/FunctionLiterals.txt b/compiler/testData/psi/FunctionLiterals.txt index a6543b322e1..c23682ac634 100644 --- a/compiler/testData/psi/FunctionLiterals.txt +++ b/compiler/testData/psi/FunctionLiterals.txt @@ -491,8 +491,6 @@ JetFile: FunctionLiterals.kt PsiElement(ARROW)('->') PsiWhiteSpace(' ') PsiElement(INTEGER_LITERAL)('1') - PsiElement(RBRACE)('}') - PsiWhiteSpace('\n') PsiElement(RBRACE)('}') - PsiErrorElement:Expecting '} - \ No newline at end of file + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/testData/psi/FunctionLiterals_ERR.txt b/compiler/testData/psi/FunctionLiterals_ERR.txt index 993b78b4145..b7ad9f8afed 100644 --- a/compiler/testData/psi/FunctionLiterals_ERR.txt +++ b/compiler/testData/psi/FunctionLiterals_ERR.txt @@ -234,158 +234,158 @@ JetFile: FunctionLiterals_ERR.kt PsiElement(ARROW)('->') PsiWhiteSpace(' ') PsiElement(IDENTIFIER)('a') - PsiElement(RBRACE)('}') - PsiWhiteSpace('\n ') - FUNCTION_LITERAL_EXPRESSION - FUNCTION_LITERAL - PsiElement(LBRACE)('{') - BLOCK - BINARY_EXPRESSION - DOT_QUALIFIED_EXPRESSION - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('T') - PsiElement(DOT)('.') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('t') - PsiWhiteSpace(' ') - OPERATION_REFERENCE - PsiElement(MINUS)('-') - PARENTHESIZED - PsiElement(LPAR)('(') - BINARY_WITH_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('a') - PsiWhiteSpace(' ') - OPERATION_REFERENCE - PsiElement(COLON)(':') - PsiWhiteSpace(' ') - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('A') - PsiElement(RPAR)(')') - PsiWhiteSpace(' ') - PsiErrorElement:Unexpected tokens (use ';' to separate expressions on the same line) - PsiElement(ARROW)('->') - PsiWhiteSpace(' ') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n ') + FUNCTION_LITERAL_EXPRESSION + FUNCTION_LITERAL + PsiElement(LBRACE)('{') + BLOCK + BINARY_EXPRESSION + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiElement(DOT)('.') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('t') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(MINUS)('-') + PARENTHESIZED + PsiElement(LPAR)('(') + BINARY_WITH_TYPE + REFERENCE_EXPRESSION PsiElement(IDENTIFIER)('a') - PsiElement(RBRACE)('}') - PsiWhiteSpace('\n\n ') - FUNCTION_LITERAL_EXPRESSION - FUNCTION_LITERAL - PsiElement(LBRACE)('{') - VALUE_PARAMETER_LIST - VALUE_PARAMETER - PsiElement(IDENTIFIER)('a') - PsiWhiteSpace(' ') - PsiErrorElement:To specify a type of a parameter or a return type, use the full notation: {(parameter : Type) : ReturnType -> ...} - PsiElement(COLON)(':') - PsiWhiteSpace(' ') - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('b') - PsiWhiteSpace(' ') - VALUE_PARAMETER - PsiErrorElement:Expecting parameter name - - PsiElement(ARROW)('->') - PsiWhiteSpace(' ') - BLOCK - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('f') - PsiElement(RBRACE)('}') - PsiWhiteSpace('\n ') - FUNCTION_LITERAL_EXPRESSION - FUNCTION_LITERAL - PsiElement(LBRACE)('{') - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('T') - PsiElement(DOT)('.') - VALUE_PARAMETER_LIST - PsiErrorElement:Expecting a parameter list in parentheses (...) - PsiElement(IDENTIFIER)('a') - PsiWhiteSpace(' ') - VALUE_PARAMETER - PsiErrorElement:Expecting parameter declaration - - PsiElement(COLON)(':') - PsiWhiteSpace(' ') - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('b') - PsiErrorElement:Expecting ') - - PsiWhiteSpace(' ') - PsiElement(ARROW)('->') - PsiWhiteSpace(' ') - BLOCK - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('f') - PsiElement(RBRACE)('}') - PsiWhiteSpace('\n\n ') - FUNCTION_LITERAL_EXPRESSION - FUNCTION_LITERAL - PsiElement(LBRACE)('{') - VALUE_PARAMETER_LIST - PsiElement(LPAR)('(') - VALUE_PARAMETER - PsiElement(IDENTIFIER)('a') - PsiElement(COMMA)(',') - PsiWhiteSpace(' ') - VALUE_PARAMETER - PsiElement(IDENTIFIER)('b') - PsiElement(RPAR)(')') - PsiErrorElement:An -> is expected - - PsiWhiteSpace(' ') - BLOCK - - PsiElement(RBRACE)('}') - PsiWhiteSpace('\n ') - FUNCTION_LITERAL_EXPRESSION - FUNCTION_LITERAL - PsiElement(LBRACE)('{') - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('T') - PsiElement(DOT)('.') - VALUE_PARAMETER_LIST - PsiElement(LPAR)('(') - VALUE_PARAMETER - PsiElement(IDENTIFIER)('a') - PsiElement(COMMA)(',') - PsiWhiteSpace(' ') - VALUE_PARAMETER - PsiElement(IDENTIFIER)('b') - PsiElement(RPAR)(')') - PsiErrorElement:An -> is expected - - PsiWhiteSpace(' ') - BLOCK - - PsiElement(RBRACE)('}') - PsiWhiteSpace('\n ') - FUNCTION_LITERAL_EXPRESSION - FUNCTION_LITERAL - PsiElement(LBRACE)('{') - VALUE_PARAMETER_LIST - VALUE_PARAMETER - PsiElement(IDENTIFIER)('a') - PsiElement(COMMA)(',') - PsiWhiteSpace(' ') - VALUE_PARAMETER - PsiErrorElement:Expecting parameter name - PsiElement(RBRACE)('}') - PsiErrorElement:Expecting '->' or ',' - - PsiWhiteSpace('\n') - BLOCK - - PsiElement(RBRACE)('}') - PsiErrorElement:Expecting '}' - \ No newline at end of file + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('A') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiErrorElement:Unexpected tokens (use ';' to separate expressions on the same line) + PsiElement(ARROW)('->') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('a') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n ') + FUNCTION_LITERAL_EXPRESSION + FUNCTION_LITERAL + PsiElement(LBRACE)('{') + VALUE_PARAMETER_LIST + VALUE_PARAMETER + PsiElement(IDENTIFIER)('a') + PsiWhiteSpace(' ') + PsiErrorElement:To specify a type of a parameter or a return type, use the full notation: {(parameter : Type) : ReturnType -> ...} + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('b') + PsiWhiteSpace(' ') + VALUE_PARAMETER + PsiErrorElement:Expecting parameter name + + PsiElement(ARROW)('->') + PsiWhiteSpace(' ') + BLOCK + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('f') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n ') + FUNCTION_LITERAL_EXPRESSION + FUNCTION_LITERAL + PsiElement(LBRACE)('{') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiElement(DOT)('.') + VALUE_PARAMETER_LIST + PsiErrorElement:Expecting a parameter list in parentheses (...) + PsiElement(IDENTIFIER)('a') + PsiWhiteSpace(' ') + VALUE_PARAMETER + PsiErrorElement:Expecting parameter declaration + + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('b') + PsiErrorElement:Expecting ') + + PsiWhiteSpace(' ') + PsiElement(ARROW)('->') + PsiWhiteSpace(' ') + BLOCK + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('f') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n ') + FUNCTION_LITERAL_EXPRESSION + FUNCTION_LITERAL + PsiElement(LBRACE)('{') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('a') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('b') + PsiElement(RPAR)(')') + PsiErrorElement:An -> is expected + + PsiWhiteSpace(' ') + BLOCK + + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n ') + FUNCTION_LITERAL_EXPRESSION + FUNCTION_LITERAL + PsiElement(LBRACE)('{') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiElement(DOT)('.') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('a') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('b') + PsiElement(RPAR)(')') + PsiErrorElement:An -> is expected + + PsiWhiteSpace(' ') + BLOCK + + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n ') + FUNCTION_LITERAL_EXPRESSION + FUNCTION_LITERAL + PsiElement(LBRACE)('{') + VALUE_PARAMETER_LIST + VALUE_PARAMETER + PsiElement(IDENTIFIER)('a') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_PARAMETER + PsiErrorElement:Expecting parameter name + PsiElement(RBRACE)('}') + PsiErrorElement:Expecting '->' or ',' + + PsiWhiteSpace('\n') + BLOCK + + PsiElement(RBRACE)('}') + PsiErrorElement:Expecting '} + \ No newline at end of file diff --git a/compiler/testData/psi/greatSyntacticShift/functionLiterals.txt b/compiler/testData/psi/greatSyntacticShift/functionLiterals.txt index b36ae66229a..e2b7ba31944 100644 --- a/compiler/testData/psi/greatSyntacticShift/functionLiterals.txt +++ b/compiler/testData/psi/greatSyntacticShift/functionLiterals.txt @@ -704,259 +704,254 @@ JetFile: functionLiterals.kt PsiElement(ARROW)('->') PsiWhiteSpace(' ') PsiElement(INTEGER_LITERAL)('1') - PsiElement(RBRACE)('}') - PsiWhiteSpace('\n') - PsiErrorElement:Expecting an element - PsiElement(COMMA)(',') - PsiWhiteSpace(' ') - FUNCTION_LITERAL_EXPRESSION - FUNCTION_LITERAL - PsiElement(LBRACE)('{') - BLOCK - DOT_QUALIFIED_EXPRESSION - CALL_EXPRESSION - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('Pair') - VALUE_ARGUMENT_LIST - PsiElement(LPAR)('(') - VALUE_ARGUMENT - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('a') - PsiElement(COMMA)(',') - PsiWhiteSpace(' ') - VALUE_ARGUMENT - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('b') - PsiElement(RPAR)(')') - PsiElement(DOT)('.') - PARENTHESIZED - PsiElement(LPAR)('(') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('y') - PsiElement(RPAR)(')') - PsiElement(RBRACE)('}') - PsiWhiteSpace('\n') - PsiErrorElement:Expecting an element - PsiElement(COMMA)(',') - PsiWhiteSpace(' ') - FUNCTION_LITERAL_EXPRESSION - FUNCTION_LITERAL - PsiElement(LBRACE)('{') - BLOCK - CALL_EXPRESSION - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('Pair') - VALUE_ARGUMENT_LIST - PsiElement(LPAR)('(') - VALUE_ARGUMENT - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('a') - PsiElement(COMMA)(',') - PsiWhiteSpace(' ') - VALUE_ARGUMENT - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('b') - PsiElement(RPAR)(')') - PsiElement(RBRACE)('}') - PsiWhiteSpace('\n') - PsiErrorElement:Expecting an element - PsiElement(COMMA)(',') - PsiWhiteSpace(' ') - FUNCTION_LITERAL_EXPRESSION - FUNCTION_LITERAL - PsiElement(LBRACE)('{') - BLOCK - DOT_QUALIFIED_EXPRESSION - CALL_EXPRESSION - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('Foo') - TYPE_ARGUMENT_LIST - PsiElement(LT)('<') - TYPE_PROJECTION - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('Bar') - PsiElement(GT)('>') - PsiElement(DOT)('.') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('x') - PsiElement(RBRACE)('}') - PsiWhiteSpace('\n') - PsiErrorElement:Expecting an element - PsiElement(COMMA)(',') - PsiWhiteSpace(' ') - FUNCTION_LITERAL_EXPRESSION - FUNCTION_LITERAL - PsiElement(LBRACE)('{') - BLOCK - DOT_QUALIFIED_EXPRESSION - CALL_EXPRESSION - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('Foo') - TYPE_ARGUMENT_LIST - PsiElement(LT)('<') - TYPE_PROJECTION - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('Bar') - PsiElement(GT)('>') - PsiElement(DOT)('.') - PARENTHESIZED - PsiElement(LPAR)('(') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('x') - PsiElement(RPAR)(')') - PsiElement(RBRACE)('}') - PsiWhiteSpace('\n') - PsiErrorElement:Expecting an element - PsiElement(COMMA)(',') - PsiWhiteSpace(' ') - FUNCTION_LITERAL_EXPRESSION - FUNCTION_LITERAL - PsiElement(LBRACE)('{') - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('Foo') - TYPE_ARGUMENT_LIST - PsiElement(LT)('<') - TYPE_PROJECTION - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('Bar') - PsiElement(GT)('>') - PsiElement(DOT)('.') - VALUE_PARAMETER_LIST - PsiElement(LPAR)('(') - VALUE_PARAMETER - PsiElement(IDENTIFIER)('x') - PsiElement(RPAR)(')') - PsiWhiteSpace(' ') - PsiElement(ARROW)('->') - PsiWhiteSpace(' ') - BLOCK - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('x') - PsiElement(RBRACE)('}') - PsiWhiteSpace('\n') - PsiErrorElement:Expecting an element - PsiElement(COMMA)(',') - PsiWhiteSpace(' ') - FUNCTION_LITERAL_EXPRESSION - FUNCTION_LITERAL - PsiElement(LBRACE)('{') - TYPE_REFERENCE - USER_TYPE - USER_TYPE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('Foo') - PsiElement(DOT)('.') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('Bar') - PsiElement(DOT)('.') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('Baz') - PsiElement(DOT)('.') - VALUE_PARAMETER_LIST - PsiElement(LPAR)('(') - VALUE_PARAMETER - PsiElement(IDENTIFIER)('x') - PsiElement(RPAR)(')') - PsiWhiteSpace(' ') - PsiElement(ARROW)('->') - PsiWhiteSpace(' ') - BLOCK - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('x') - PsiElement(RBRACE)('}') - PsiWhiteSpace('\n') - PsiErrorElement:Expecting an element - PsiElement(COMMA)(',') - PsiWhiteSpace(' ') - FUNCTION_LITERAL_EXPRESSION - FUNCTION_LITERAL - PsiElement(LBRACE)('{') - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('Foo') - TYPE_ARGUMENT_LIST - PsiElement(LT)('<') - TYPE_PROJECTION - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('Bar') - PsiElement(GT)('>') - PsiElement(DOT)('.') - VALUE_PARAMETER_LIST - PsiElement(LPAR)('(') - VALUE_PARAMETER - PsiElement(IDENTIFIER)('x') - PsiElement(RPAR)(')') - PsiWhiteSpace(' ') - PsiElement(COLON)(':') - PsiWhiteSpace(' ') - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('Int') - PsiWhiteSpace(' ') - PsiElement(ARROW)('->') - PsiWhiteSpace(' ') - BLOCK - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('x') - PsiElement(RBRACE)('}') - PsiWhiteSpace('\n') - PsiErrorElement:Expecting an element - PsiElement(COMMA)(',') - PsiWhiteSpace(' ') - FUNCTION_LITERAL_EXPRESSION - FUNCTION_LITERAL - PsiElement(LBRACE)('{') - TYPE_REFERENCE - USER_TYPE - USER_TYPE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('Foo') - PsiElement(DOT)('.') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('Bar') - PsiElement(DOT)('.') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('Baz') - PsiElement(DOT)('.') - VALUE_PARAMETER_LIST - PsiElement(LPAR)('(') - VALUE_PARAMETER - PsiElement(IDENTIFIER)('x') - PsiElement(RPAR)(')') - PsiWhiteSpace(' ') - PsiElement(COLON)(':') - PsiWhiteSpace(' ') - TYPE_REFERENCE - USER_TYPE - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('Int') - PsiWhiteSpace(' ') - PsiElement(ARROW)('->') - PsiWhiteSpace(' ') - BLOCK - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('x') - PsiElement(RBRACE)('}') - PsiWhiteSpace('\n') - PsiErrorElement:Expecting an element - PsiElement(RPAR)(')') - PsiWhiteSpace('\n') PsiElement(RBRACE)('}') - PsiErrorElement:Expecting ')' - - PsiErrorElement:Expecting '} - \ No newline at end of file + PsiWhiteSpace('\n') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_ARGUMENT + FUNCTION_LITERAL_EXPRESSION + FUNCTION_LITERAL + PsiElement(LBRACE)('{') + BLOCK + DOT_QUALIFIED_EXPRESSION + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Pair') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('a') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_ARGUMENT + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('b') + PsiElement(RPAR)(')') + PsiElement(DOT)('.') + PARENTHESIZED + PsiElement(LPAR)('(') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('y') + PsiElement(RPAR)(')') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_ARGUMENT + FUNCTION_LITERAL_EXPRESSION + FUNCTION_LITERAL + PsiElement(LBRACE)('{') + BLOCK + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Pair') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('a') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_ARGUMENT + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('b') + PsiElement(RPAR)(')') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_ARGUMENT + FUNCTION_LITERAL_EXPRESSION + FUNCTION_LITERAL + PsiElement(LBRACE)('{') + BLOCK + DOT_QUALIFIED_EXPRESSION + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Foo') + TYPE_ARGUMENT_LIST + PsiElement(LT)('<') + TYPE_PROJECTION + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Bar') + PsiElement(GT)('>') + PsiElement(DOT)('.') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_ARGUMENT + FUNCTION_LITERAL_EXPRESSION + FUNCTION_LITERAL + PsiElement(LBRACE)('{') + BLOCK + DOT_QUALIFIED_EXPRESSION + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Foo') + TYPE_ARGUMENT_LIST + PsiElement(LT)('<') + TYPE_PROJECTION + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Bar') + PsiElement(GT)('>') + PsiElement(DOT)('.') + PARENTHESIZED + PsiElement(LPAR)('(') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x') + PsiElement(RPAR)(')') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_ARGUMENT + FUNCTION_LITERAL_EXPRESSION + FUNCTION_LITERAL + PsiElement(LBRACE)('{') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Foo') + TYPE_ARGUMENT_LIST + PsiElement(LT)('<') + TYPE_PROJECTION + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Bar') + PsiElement(GT)('>') + PsiElement(DOT)('.') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(ARROW)('->') + PsiWhiteSpace(' ') + BLOCK + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_ARGUMENT + FUNCTION_LITERAL_EXPRESSION + FUNCTION_LITERAL + PsiElement(LBRACE)('{') + TYPE_REFERENCE + USER_TYPE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Foo') + PsiElement(DOT)('.') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Bar') + PsiElement(DOT)('.') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Baz') + PsiElement(DOT)('.') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(ARROW)('->') + PsiWhiteSpace(' ') + BLOCK + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_ARGUMENT + FUNCTION_LITERAL_EXPRESSION + FUNCTION_LITERAL + PsiElement(LBRACE)('{') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Foo') + TYPE_ARGUMENT_LIST + PsiElement(LT)('<') + TYPE_PROJECTION + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Bar') + PsiElement(GT)('>') + PsiElement(DOT)('.') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiWhiteSpace(' ') + PsiElement(ARROW)('->') + PsiWhiteSpace(' ') + BLOCK + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_ARGUMENT + FUNCTION_LITERAL_EXPRESSION + FUNCTION_LITERAL + PsiElement(LBRACE)('{') + TYPE_REFERENCE + USER_TYPE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Foo') + PsiElement(DOT)('.') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Bar') + PsiElement(DOT)('.') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Baz') + PsiElement(DOT)('.') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + VALUE_PARAMETER + PsiElement(IDENTIFIER)('x') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(COLON)(':') + PsiWhiteSpace(' ') + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('Int') + PsiWhiteSpace(' ') + PsiElement(ARROW)('->') + PsiWhiteSpace(' ') + BLOCK + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + PsiElement(RPAR)(')') + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/testData/psi/recovery/InvalidCharInSingleLineLambda.kt b/compiler/testData/psi/recovery/InvalidCharInSingleLineLambda.kt new file mode 100644 index 00000000000..fab86af47ad --- /dev/null +++ b/compiler/testData/psi/recovery/InvalidCharInSingleLineLambda.kt @@ -0,0 +1,7 @@ +// checks that invalid characters (inserted e.g. by completion) inside single-line block do not cause wrong scopes for declarations below +fun foo() { + x { v.s$ } + val v = "" +} + +fun bar() { } \ No newline at end of file diff --git a/compiler/testData/psi/recovery/InvalidCharInSingleLineLambda.txt b/compiler/testData/psi/recovery/InvalidCharInSingleLineLambda.txt new file mode 100644 index 00000000000..57068e7e5c4 --- /dev/null +++ b/compiler/testData/psi/recovery/InvalidCharInSingleLineLambda.txt @@ -0,0 +1,62 @@ +JetFile: InvalidCharInSingleLineLambda.kt + PsiComment(EOL_COMMENT)('// checks that invalid characters (inserted e.g. by completion) inside single-line block do not cause wrong scopes for declarations below') + PsiWhiteSpace('\n') + PACKAGE_DIRECTIVE + + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x') + PsiWhiteSpace(' ') + FUNCTION_LITERAL_ARGUMENT + FUNCTION_LITERAL_EXPRESSION + FUNCTION_LITERAL + PsiElement(LBRACE)('{') + PsiWhiteSpace(' ') + BLOCK + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('v') + PsiElement(DOT)('.') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('s') + PsiErrorElement:Unexpected tokens (use ';' to separate expressions on the same line) + PsiElement(BAD_CHARACTER)('$') + PsiWhiteSpace(' ') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n ') + PROPERTY + PsiElement(val)('val') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('v') + PsiWhiteSpace(' ') + PsiElement(EQ)('=') + PsiWhiteSpace(' ') + STRING_TEMPLATE + PsiElement(OPEN_QUOTE)('"') + PsiElement(CLOSING_QUOTE)('"') + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('bar') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace(' ') + PsiElement(RBRACE)('}') \ No newline at end of file diff --git a/compiler/testData/psi/recovery/SameLineStatementRecovery.txt b/compiler/testData/psi/recovery/SameLineStatementRecovery.txt index a89cbf6b29a..cd5e533067c 100644 --- a/compiler/testData/psi/recovery/SameLineStatementRecovery.txt +++ b/compiler/testData/psi/recovery/SameLineStatementRecovery.txt @@ -625,14 +625,19 @@ JetFile: SameLineStatementRecovery.kt PsiElement(IDENTIFIER)('get') PsiElement(LPAR)('(') PsiElement(RPAR)(')') - PsiWhiteSpace(' ') - PsiElement(LBRACE)('{') - PsiWhiteSpace(' ') - PsiElement(return)('return') - PsiWhiteSpace(' ') - PsiElement(INTEGER_LITERAL)('12') - PsiWhiteSpace(' ') - PsiElement(RBRACE)('}') + PsiWhiteSpace(' ') + FUNCTION_LITERAL_EXPRESSION + FUNCTION_LITERAL + PsiElement(LBRACE)('{') + PsiWhiteSpace(' ') + BLOCK + RETURN + PsiElement(return)('return') + PsiWhiteSpace(' ') + INTEGER_CONSTANT + PsiElement(INTEGER_LITERAL)('12') + PsiWhiteSpace(' ') + PsiElement(RBRACE)('}') PsiWhiteSpace('\n') PsiElement(RBRACE)('}') PsiWhiteSpace('\n\n') diff --git a/compiler/tests/org/jetbrains/jet/parsing/JetParsingTestGenerated.java b/compiler/tests/org/jetbrains/jet/parsing/JetParsingTestGenerated.java index e0982ffe482..b4107748da5 100644 --- a/compiler/tests/org/jetbrains/jet/parsing/JetParsingTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/parsing/JetParsingTestGenerated.java @@ -1269,6 +1269,12 @@ public class JetParsingTestGenerated extends AbstractJetParsingTest { doParsingTest(fileName); } + @TestMetadata("InvalidCharInSingleLineLambda.kt") + public void testInvalidCharInSingleLineLambda() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/recovery/InvalidCharInSingleLineLambda.kt"); + doParsingTest(fileName); + } + @TestMetadata("kt2172.kt") public void testKt2172() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/recovery/kt2172.kt"); diff --git a/idea/testData/completion/basic/common/InFunctionLiteral.kt b/idea/testData/completion/basic/common/InFunctionLiteral.kt new file mode 100644 index 00000000000..068ec35333c --- /dev/null +++ b/idea/testData/completion/basic/common/InFunctionLiteral.kt @@ -0,0 +1,9 @@ +fun foo(p: Iterable) { + p.filter { it. } +} + +trait D { + fun bar() +} + +// EXIST: bar diff --git a/idea/tests/org/jetbrains/jet/completion/JSBasicCompletionTestGenerated.java b/idea/tests/org/jetbrains/jet/completion/JSBasicCompletionTestGenerated.java index dd64e7e1eb3..3806a8d42f1 100644 --- a/idea/tests/org/jetbrains/jet/completion/JSBasicCompletionTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/completion/JSBasicCompletionTestGenerated.java @@ -364,6 +364,12 @@ public class JSBasicCompletionTestGenerated extends AbstractJSBasicCompletionTes doTest(fileName); } + @TestMetadata("InFunctionLiteral.kt") + public void testInFunctionLiteral() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/InFunctionLiteral.kt"); + doTest(fileName); + } + @TestMetadata("InGlobalPropertyInitializer.kt") public void testInGlobalPropertyInitializer() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/InGlobalPropertyInitializer.kt"); diff --git a/idea/tests/org/jetbrains/jet/completion/JvmBasicCompletionTestGenerated.java b/idea/tests/org/jetbrains/jet/completion/JvmBasicCompletionTestGenerated.java index 2fb5837d89d..52d5528f505 100644 --- a/idea/tests/org/jetbrains/jet/completion/JvmBasicCompletionTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/completion/JvmBasicCompletionTestGenerated.java @@ -364,6 +364,12 @@ public class JvmBasicCompletionTestGenerated extends AbstractJvmBasicCompletionT doTest(fileName); } + @TestMetadata("InFunctionLiteral.kt") + public void testInFunctionLiteral() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/InFunctionLiteral.kt"); + doTest(fileName); + } + @TestMetadata("InGlobalPropertyInitializer.kt") public void testInGlobalPropertyInitializer() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/completion/basic/common/InGlobalPropertyInitializer.kt");