@@ -1089,23 +1089,31 @@ object Parsers {
1089
1089
* something enclosed in (...) or [...], and this is followed by a `=>` or `?=>`
1090
1090
* and an INDENT.
1091
1091
*/
1092
- def followingIsLambdaAfterColon (): Boolean =
1092
+ def followingIsLambdaAfterColon (): Option [() => Tree ] =
1093
1093
val lookahead = in.LookaheadScanner (allowIndent = true )
1094
1094
.tap(_.currentRegion.knownWidth = in.currentRegion.indentWidth)
1095
- def isArrowIndent () =
1096
- lookahead.isArrow
1097
- && {
1095
+ def isArrowIndent (): Option [() => Tree ] =
1096
+ if lookahead.isArrow then
1098
1097
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
1101
1108
lookahead.nextToken()
1102
1109
if lookahead.isIdent || lookahead.token == USCORE then
1103
1110
lookahead.nextToken()
1104
1111
isArrowIndent()
1105
1112
else if lookahead.token == LPAREN || lookahead.token == LBRACKET then
1106
1113
lookahead.skipParens()
1107
1114
isArrowIndent()
1108
- else false
1115
+ else
1116
+ None
1109
1117
1110
1118
/** Can the next lookahead token start an operand as defined by
1111
1119
* leadingOperandTokens, or is postfix ops enabled?
@@ -1174,8 +1182,10 @@ object Parsers {
1174
1182
* : (params) =>
1175
1183
* body
1176
1184
*/
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
1179
1189
1180
1190
/** operand { infixop operand | MatchClause } [postfixop],
1181
1191
*
@@ -1199,17 +1209,19 @@ object Parsers {
1199
1209
opStack = OpInfo (top1, op, in.offset) :: opStack
1200
1210
colonAtEOLOpt()
1201
1211
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))
1213
1225
else
1214
1226
val t = reduceStack(base, top, minPrec, leftAssoc = true , in.name, isType)
1215
1227
if ! isType && in.token == MATCH then recurAtMinPrec(matchClause(t))
@@ -2848,12 +2860,14 @@ object Parsers {
2848
2860
makeParameter(name.asTermName, typedOpt(), Modifiers (), isBackquoted = isBackquoted(id))
2849
2861
}
2850
2862
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
2857
2871
end simpleExprRest
2858
2872
2859
2873
/** SimpleExpr ::= ‘new’ ConstrApp {`with` ConstrApp} [TemplateBody]
0 commit comments