@@ -984,6 +984,13 @@ object Parsers {
984
984
recur(top)
985
985
}
986
986
987
+ /** True if we are seeing a lambda argument after a colon of the form:
988
+ * : (params) =>
989
+ * body
990
+ */
991
+ def isColonLambda =
992
+ in.fewerBracesEnabled && in.token == COLONfollow && followingIsLambdaAfterColon()
993
+
987
994
/** operand { infixop operand | MatchClause } [postfixop],
988
995
*
989
996
* respecting rules of associativity and precedence.
@@ -998,24 +1005,25 @@ object Parsers {
998
1005
val base = opStack
999
1006
1000
1007
def recur (top : Tree ): Tree =
1001
- val isType = kind == ParseKind .Type
1002
- if (isIdent && isOperator) {
1008
+ def isType = kind == ParseKind .Type
1009
+ def maybePostfix = kind == ParseKind .Expr && in.postfixOpsEnabled
1010
+ if isIdent && isOperator then
1003
1011
val op = if isType then typeIdent() else termIdent()
1004
1012
val top1 = reduceStack(base, top, precedence(op.name), ! op.name.isRightAssocOperatorName, op.name, isType)
1005
1013
opStack = OpInfo (top1, op, in.offset) :: opStack
1006
1014
colonAtEOLOpt()
1007
1015
newLineOptWhenFollowing(canStartOperand)
1008
- val maybePostfix = kind == ParseKind .Expr && in.postfixOpsEnabled
1009
- if (maybePostfix && ! canStartOperand(in.token)) {
1016
+ if isColonLambda then
1017
+ in.nextToken()
1018
+ recur(expr(Location .InColonArg ))
1019
+ else if maybePostfix && ! canStartOperand(in.token) then
1010
1020
val topInfo = opStack.head
1011
1021
opStack = opStack.tail
1012
1022
val od = reduceStack(base, topInfo.operand, 0 , true , in.name, isType)
1013
1023
atSpan(startOffset(od), topInfo.offset) {
1014
1024
PostfixOp (od, topInfo.operator)
1015
1025
}
1016
- }
1017
1026
else recur(operand(location))
1018
- }
1019
1027
else
1020
1028
val t = reduceStack(base, top, minPrec, leftAssoc = true , in.name, isType)
1021
1029
if ! isType && in.token == MATCH then recurAtMinPrec(matchClause(t))
@@ -2399,7 +2407,7 @@ object Parsers {
2399
2407
makeParameter(name.asTermName, typedOpt(), Modifiers (), isBackquoted = isBackquoted(id))
2400
2408
}
2401
2409
case _ => t
2402
- else if in.fewerBracesEnabled && in.token == COLONfollow && followingIsLambdaAfterColon() then
2410
+ else if isColonLambda then
2403
2411
val app = atSpan(startOffset(t), in.skipToken()) {
2404
2412
Apply (t, expr(Location .InColonArg ) :: Nil )
2405
2413
}
0 commit comments