@@ -1089,23 +1089,31 @@ object Parsers {
10891089 * something enclosed in (...) or [...], and this is followed by a `=>` or `?=>`
10901090 * and an INDENT.
10911091 */
1092- def followingIsLambdaAfterColon (): Boolean =
1092+ def followingIsLambdaAfterColon (): Option [() => Tree ] =
10931093 val lookahead = in.LookaheadScanner (allowIndent = true )
10941094 .tap(_.currentRegion.knownWidth = in.currentRegion.indentWidth)
1095- def isArrowIndent () =
1096- lookahead.isArrow
1097- && {
1095+ def isArrowIndent (): Option [() => Tree ] =
1096+ if lookahead.isArrow then
10981097 lookahead.observeArrowIndented()
1099- lookahead.token == INDENT || lookahead.token == EOF
1100- }
1098+ if lookahead.token == INDENT || lookahead.token == EOF then
1099+ Some (() => expr(Location .InColonArg ))
1100+ else if ! in.currentRegion.isInstanceOf [InParens ] then
1101+ Some : () =>
1102+ val t = inSepRegion(SingleLineLambda (_)):
1103+ expr(Location .InColonArg )
1104+ accept(ENDLAMBDA )
1105+ t
1106+ else None
1107+ else None
11011108 lookahead.nextToken()
11021109 if lookahead.isIdent || lookahead.token == USCORE then
11031110 lookahead.nextToken()
11041111 isArrowIndent()
11051112 else if lookahead.token == LPAREN || lookahead.token == LBRACKET then
11061113 lookahead.skipParens()
11071114 isArrowIndent()
1108- else false
1115+ else
1116+ None
11091117
11101118 /** Can the next lookahead token start an operand as defined by
11111119 * leadingOperandTokens, or is postfix ops enabled?
@@ -1174,8 +1182,10 @@ object Parsers {
11741182 * : (params) =>
11751183 * body
11761184 */
1177- def isColonLambda =
1178- sourceVersion.enablesFewerBraces && in.token == COLONfollow && followingIsLambdaAfterColon()
1185+ def isColonLambda : Option [() => Tree ] =
1186+ if sourceVersion.enablesFewerBraces && in.token == COLONfollow
1187+ then followingIsLambdaAfterColon()
1188+ else None
11791189
11801190 /** operand { infixop operand | MatchClause } [postfixop],
11811191 *
@@ -1199,17 +1209,19 @@ object Parsers {
11991209 opStack = OpInfo (top1, op, in.offset) :: opStack
12001210 colonAtEOLOpt()
12011211 newLineOptWhenFollowing(canStartOperand)
1202- if isColonLambda then
1203- in.nextToken()
1204- recur(expr(Location .InColonArg ))
1205- else if maybePostfix && ! canStartOperand(in.token) then
1206- val topInfo = opStack.head
1207- opStack = opStack.tail
1208- val od = reduceStack(base, topInfo.operand, 0 , true , in.name, isType)
1209- atSpan(startOffset(od), topInfo.offset) {
1210- PostfixOp (od, topInfo.operator)
1211- }
1212- else recur(operand(location))
1212+ isColonLambda match
1213+ case Some (parseExpr) =>
1214+ in.nextToken()
1215+ recur(parseExpr())
1216+ case _ =>
1217+ if maybePostfix && ! canStartOperand(in.token) then
1218+ val topInfo = opStack.head
1219+ opStack = opStack.tail
1220+ val od = reduceStack(base, topInfo.operand, 0 , true , in.name, isType)
1221+ atSpan(startOffset(od), topInfo.offset) {
1222+ PostfixOp (od, topInfo.operator)
1223+ }
1224+ else recur(operand(location))
12131225 else
12141226 val t = reduceStack(base, top, minPrec, leftAssoc = true , in.name, isType)
12151227 if ! isType && in.token == MATCH then recurAtMinPrec(matchClause(t))
@@ -2848,12 +2860,14 @@ object Parsers {
28482860 makeParameter(name.asTermName, typedOpt(), Modifiers (), isBackquoted = isBackquoted(id))
28492861 }
28502862 case _ => t
2851- else if isColonLambda then
2852- val app = atSpan(startOffset(t), in.skipToken()) {
2853- Apply (t, expr(Location .InColonArg ) :: Nil )
2854- }
2855- simpleExprRest(app, location, canApply = true )
2856- else t
2863+ else isColonLambda match
2864+ case Some (parseExpr) =>
2865+ val app =
2866+ atSpan(startOffset(t), in.skipToken()):
2867+ Apply (t, parseExpr() :: Nil )
2868+ simpleExprRest(app, location, canApply = true )
2869+ case None =>
2870+ t
28572871 end simpleExprRest
28582872
28592873 /** SimpleExpr ::= ‘new’ ConstrApp {`with` ConstrApp} [TemplateBody]
0 commit comments