Allowed shorthand parameter list with type reference in lambda.
This commit is contained in:
@@ -1033,7 +1033,6 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
|||||||
PsiBuilder.Marker rollbackMarker = mark();
|
PsiBuilder.Marker rollbackMarker = mark();
|
||||||
boolean preferParamsToExpressions = (lookahead(1) == COMMA);
|
boolean preferParamsToExpressions = (lookahead(1) == COMMA);
|
||||||
parseFunctionLiteralShorthandParameterList();
|
parseFunctionLiteralShorthandParameterList();
|
||||||
parseOptionalFunctionLiteralType();
|
|
||||||
|
|
||||||
paramsFound = preferParamsToExpressions ?
|
paramsFound = preferParamsToExpressions ?
|
||||||
rollbackOrDrop(rollbackMarker, ARROW, "An -> is expected", RBRACE) :
|
rollbackOrDrop(rollbackMarker, ARROW, "An -> is expected", RBRACE) :
|
||||||
@@ -1112,15 +1111,13 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
|||||||
|
|
||||||
expect(IDENTIFIER, "Expecting parameter name", TokenSet.create(ARROW));
|
expect(IDENTIFIER, "Expecting parameter name", TokenSet.create(ARROW));
|
||||||
|
|
||||||
|
if (at(COLON)) {
|
||||||
|
advance(); // COLON
|
||||||
|
myJetParsing.parseTypeRef(TokenSet.create(ARROW, COMMA));
|
||||||
|
}
|
||||||
parameter.done(VALUE_PARAMETER);
|
parameter.done(VALUE_PARAMETER);
|
||||||
|
|
||||||
if (at(COLON)) {
|
if (at(ARROW)) {
|
||||||
PsiBuilder.Marker errorMarker = mark();
|
|
||||||
advance(); // COLON
|
|
||||||
myJetParsing.parseTypeRef();
|
|
||||||
errorMarker.error("To specify a type of a parameter or a return type, use the full notation: {(parameter : Type) : ReturnType -> ...}");
|
|
||||||
}
|
|
||||||
else if (at(ARROW)) {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (at(COMMA)) {
|
else if (at(COMMA)) {
|
||||||
|
|||||||
@@ -31,4 +31,12 @@ fun foo() {
|
|||||||
{((a: Int = object { fun t() {} }) -> Int).(x: Int) : String -> "" }
|
{((a: Int = object { fun t() {} }) -> Int).(x: Int) : String -> "" }
|
||||||
{ A.B<String>.(x: Int) -> }
|
{ A.B<String>.(x: Int) -> }
|
||||||
{((a: Boolean = true) -> Int).(x: Any) : Unit -> }
|
{((a: Boolean = true) -> Int).(x: Any) : Unit -> }
|
||||||
|
|
||||||
|
{a: b -> f}
|
||||||
|
{a: b, c -> f}
|
||||||
|
{a: b, c: d -> f}
|
||||||
|
{a: (Int) -> Unit, c: (Int) -> Unit -> f}
|
||||||
|
|
||||||
|
//{a: ((Int) -> Unit) ->} todo
|
||||||
|
//{[a] a: A -> }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -664,5 +664,139 @@ JetFile: FunctionLiterals.kt
|
|||||||
BLOCK
|
BLOCK
|
||||||
<empty list>
|
<empty list>
|
||||||
PsiElement(RBRACE)('}')
|
PsiElement(RBRACE)('}')
|
||||||
|
PsiWhiteSpace('\n\n ')
|
||||||
|
FUNCTION_LITERAL_EXPRESSION
|
||||||
|
FUNCTION_LITERAL
|
||||||
|
PsiElement(LBRACE)('{')
|
||||||
|
VALUE_PARAMETER_LIST
|
||||||
|
VALUE_PARAMETER
|
||||||
|
PsiElement(IDENTIFIER)('a')
|
||||||
|
PsiElement(COLON)(':')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('b')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(ARROW)('->')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
BLOCK
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('f')
|
||||||
|
PsiElement(RBRACE)('}')
|
||||||
|
PsiWhiteSpace('\n ')
|
||||||
|
FUNCTION_LITERAL_EXPRESSION
|
||||||
|
FUNCTION_LITERAL
|
||||||
|
PsiElement(LBRACE)('{')
|
||||||
|
VALUE_PARAMETER_LIST
|
||||||
|
VALUE_PARAMETER
|
||||||
|
PsiElement(IDENTIFIER)('a')
|
||||||
|
PsiElement(COLON)(':')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('b')
|
||||||
|
PsiElement(COMMA)(',')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
VALUE_PARAMETER
|
||||||
|
PsiElement(IDENTIFIER)('c')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(ARROW)('->')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
BLOCK
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('f')
|
||||||
|
PsiElement(RBRACE)('}')
|
||||||
|
PsiWhiteSpace('\n ')
|
||||||
|
FUNCTION_LITERAL_EXPRESSION
|
||||||
|
FUNCTION_LITERAL
|
||||||
|
PsiElement(LBRACE)('{')
|
||||||
|
VALUE_PARAMETER_LIST
|
||||||
|
VALUE_PARAMETER
|
||||||
|
PsiElement(IDENTIFIER)('a')
|
||||||
|
PsiElement(COLON)(':')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('b')
|
||||||
|
PsiElement(COMMA)(',')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
VALUE_PARAMETER
|
||||||
|
PsiElement(IDENTIFIER)('c')
|
||||||
|
PsiElement(COLON)(':')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('d')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(ARROW)('->')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
BLOCK
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('f')
|
||||||
|
PsiElement(RBRACE)('}')
|
||||||
|
PsiWhiteSpace('\n ')
|
||||||
|
FUNCTION_LITERAL_EXPRESSION
|
||||||
|
FUNCTION_LITERAL
|
||||||
|
PsiElement(LBRACE)('{')
|
||||||
|
VALUE_PARAMETER_LIST
|
||||||
|
VALUE_PARAMETER
|
||||||
|
PsiElement(IDENTIFIER)('a')
|
||||||
|
PsiElement(COLON)(':')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
TYPE_REFERENCE
|
||||||
|
FUNCTION_TYPE
|
||||||
|
VALUE_PARAMETER_LIST
|
||||||
|
PsiElement(LPAR)('(')
|
||||||
|
VALUE_PARAMETER
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('Int')
|
||||||
|
PsiElement(RPAR)(')')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(ARROW)('->')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('Unit')
|
||||||
|
PsiElement(COMMA)(',')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
VALUE_PARAMETER
|
||||||
|
PsiElement(IDENTIFIER)('c')
|
||||||
|
PsiElement(COLON)(':')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
TYPE_REFERENCE
|
||||||
|
FUNCTION_TYPE
|
||||||
|
VALUE_PARAMETER_LIST
|
||||||
|
PsiElement(LPAR)('(')
|
||||||
|
VALUE_PARAMETER
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('Int')
|
||||||
|
PsiElement(RPAR)(')')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(ARROW)('->')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('Unit')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(ARROW)('->')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
BLOCK
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('f')
|
||||||
|
PsiElement(RBRACE)('}')
|
||||||
|
PsiWhiteSpace('\n\n ')
|
||||||
|
PsiComment(EOL_COMMENT)('//{a: ((Int) -> Unit) ->} todo')
|
||||||
|
PsiWhiteSpace('\n ')
|
||||||
|
PsiComment(EOL_COMMENT)('//{[a] a: A -> }')
|
||||||
PsiWhiteSpace('\n')
|
PsiWhiteSpace('\n')
|
||||||
PsiElement(RBRACE)('}')
|
PsiElement(RBRACE)('}')
|
||||||
@@ -13,7 +13,14 @@ fun foo() {
|
|||||||
{T.t(a) -> a}
|
{T.t(a) -> a}
|
||||||
{T.t -(a : A) -> a}
|
{T.t -(a : A) -> a}
|
||||||
|
|
||||||
{a : b -> f}
|
{a : b, -> f}
|
||||||
|
{a : , c -> f}
|
||||||
|
{a : -> f}
|
||||||
|
{a, -> f}
|
||||||
|
|
||||||
|
{a : b, }
|
||||||
|
{a : , }
|
||||||
|
|
||||||
{T.a : b -> f}
|
{T.a : b -> f}
|
||||||
|
|
||||||
{(a, b) }
|
{(a, b) }
|
||||||
|
|||||||
@@ -277,14 +277,14 @@ JetFile: FunctionLiterals_ERR.kt
|
|||||||
VALUE_PARAMETER_LIST
|
VALUE_PARAMETER_LIST
|
||||||
VALUE_PARAMETER
|
VALUE_PARAMETER
|
||||||
PsiElement(IDENTIFIER)('a')
|
PsiElement(IDENTIFIER)('a')
|
||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
PsiErrorElement:To specify a type of a parameter or a return type, use the full notation: {(parameter : Type) : ReturnType -> ...}
|
|
||||||
PsiElement(COLON)(':')
|
PsiElement(COLON)(':')
|
||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
TYPE_REFERENCE
|
TYPE_REFERENCE
|
||||||
USER_TYPE
|
USER_TYPE
|
||||||
REFERENCE_EXPRESSION
|
REFERENCE_EXPRESSION
|
||||||
PsiElement(IDENTIFIER)('b')
|
PsiElement(IDENTIFIER)('b')
|
||||||
|
PsiElement(COMMA)(',')
|
||||||
PsiWhiteSpace(' ')
|
PsiWhiteSpace(' ')
|
||||||
VALUE_PARAMETER
|
VALUE_PARAMETER
|
||||||
PsiErrorElement:Expecting parameter name
|
PsiErrorElement:Expecting parameter name
|
||||||
@@ -296,6 +296,106 @@ JetFile: FunctionLiterals_ERR.kt
|
|||||||
PsiElement(IDENTIFIER)('f')
|
PsiElement(IDENTIFIER)('f')
|
||||||
PsiElement(RBRACE)('}')
|
PsiElement(RBRACE)('}')
|
||||||
PsiWhiteSpace('\n ')
|
PsiWhiteSpace('\n ')
|
||||||
|
FUNCTION_LITERAL_EXPRESSION
|
||||||
|
FUNCTION_LITERAL
|
||||||
|
PsiElement(LBRACE)('{')
|
||||||
|
VALUE_PARAMETER_LIST
|
||||||
|
VALUE_PARAMETER
|
||||||
|
PsiElement(IDENTIFIER)('a')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(COLON)(':')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
TYPE_REFERENCE
|
||||||
|
PsiErrorElement:Type expected
|
||||||
|
<empty list>
|
||||||
|
PsiElement(COMMA)(',')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
VALUE_PARAMETER
|
||||||
|
PsiElement(IDENTIFIER)('c')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(ARROW)('->')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
BLOCK
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('f')
|
||||||
|
PsiElement(RBRACE)('}')
|
||||||
|
PsiWhiteSpace('\n ')
|
||||||
|
FUNCTION_LITERAL_EXPRESSION
|
||||||
|
FUNCTION_LITERAL
|
||||||
|
PsiElement(LBRACE)('{')
|
||||||
|
VALUE_PARAMETER_LIST
|
||||||
|
VALUE_PARAMETER
|
||||||
|
PsiElement(IDENTIFIER)('a')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(COLON)(':')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
TYPE_REFERENCE
|
||||||
|
PsiErrorElement:Type expected
|
||||||
|
<empty list>
|
||||||
|
PsiElement(ARROW)('->')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
BLOCK
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('f')
|
||||||
|
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
|
||||||
|
<empty list>
|
||||||
|
PsiElement(ARROW)('->')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
BLOCK
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('f')
|
||||||
|
PsiElement(RBRACE)('}')
|
||||||
|
PsiWhiteSpace('\n\n ')
|
||||||
|
FUNCTION_LITERAL_EXPRESSION
|
||||||
|
FUNCTION_LITERAL
|
||||||
|
PsiElement(LBRACE)('{')
|
||||||
|
BLOCK
|
||||||
|
BINARY_WITH_TYPE
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('a')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
OPERATION_REFERENCE
|
||||||
|
PsiElement(COLON)(':')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
TYPE_REFERENCE
|
||||||
|
USER_TYPE
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('b')
|
||||||
|
PsiErrorElement:Unexpected tokens (use ';' to separate expressions on the same line)
|
||||||
|
PsiElement(COMMA)(',')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(RBRACE)('}')
|
||||||
|
PsiWhiteSpace('\n ')
|
||||||
|
FUNCTION_LITERAL_EXPRESSION
|
||||||
|
FUNCTION_LITERAL
|
||||||
|
PsiElement(LBRACE)('{')
|
||||||
|
BLOCK
|
||||||
|
BINARY_WITH_TYPE
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('a')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
OPERATION_REFERENCE
|
||||||
|
PsiElement(COLON)(':')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
TYPE_REFERENCE
|
||||||
|
PsiErrorElement:Type expected
|
||||||
|
<empty list>
|
||||||
|
PsiErrorElement:Unexpected tokens (use ';' to separate expressions on the same line)
|
||||||
|
PsiElement(COMMA)(',')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(RBRACE)('}')
|
||||||
|
PsiWhiteSpace('\n\n ')
|
||||||
FUNCTION_LITERAL_EXPRESSION
|
FUNCTION_LITERAL_EXPRESSION
|
||||||
FUNCTION_LITERAL
|
FUNCTION_LITERAL
|
||||||
PsiElement(LBRACE)('{')
|
PsiElement(LBRACE)('{')
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ fun test(some: (Int) -> Int) {
|
|||||||
|
|
||||||
fun foo() = test() {it}
|
fun foo() = test() {it}
|
||||||
val function = test {(a: Int) -> a}
|
val function = test {(a: Int) -> a}
|
||||||
val function1 = test {a : Int -> a}
|
val function1 = test {a: Int -> a}
|
||||||
val function2 = test { }
|
val function2 = test { }
|
||||||
val function3 = test {}
|
val function3 = test {}
|
||||||
val function4 = test { }
|
val function4 = test { }
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ fun test(some: (Int) -> Int) {
|
|||||||
|
|
||||||
fun foo() = test() { it }
|
fun foo() = test() { it }
|
||||||
val function = test {(a: Int) -> a }
|
val function = test {(a: Int) -> a }
|
||||||
val function1 = test { a : Int -> a }
|
val function1 = test { a: Int -> a }
|
||||||
val function2 = test { }
|
val function2 = test { }
|
||||||
val function3 = test {}
|
val function3 = test {}
|
||||||
val function4 = test { }
|
val function4 = test { }
|
||||||
|
|||||||
Reference in New Issue
Block a user