@@ -1086,18 +1086,20 @@ object Parsers {
1086
1086
1087
1087
/** Is the token sequence following the current `:` token classified as a lambda?
1088
1088
* If yes return a defined parsing function to parse the lambda body, if not
1089
- * return None. The case is triggered in two :if the input starts with an identifier,
1090
- * a wildcard, or something enclosed in (...) or [...], this is followed by a
1091
- * `=>` or `?=>`, one one of the following two cases applies:
1092
- * 1. The next token is an indent. In this case the return parsing function parses
1093
- * an Expr in location Location.InColonArg.
1094
- * 2. The next token is on the same line and the enclosing region is not `(...)`.
1095
- * In this case the parsing function parses an Expr in location Location.InColonArg
1096
- * enclosed in a SingleLineLambda region, and then eats the ENDlambda token
1097
- * generated by the Scanner at the end of that region.
1098
- * The reason for excluding (2) in regions enclosed in parentheses is to avoid
1099
- * an ambiguity with type ascription `(x: A => B)`, where function types are only
1100
- * allowed inside parentheses.
1089
+ * return None. The case is triggered in two situations:
1090
+ * 1. If the input starts with an identifier, a wildcard, or something
1091
+ * enclosed in (...) or [...], this is followed by a `=>` or `?=>`,
1092
+ * and one of the following two subcases applies:
1093
+ * 1a. The next token is an indent. In this case the return parsing function parses
1094
+ * an Expr in location Location.InColonArg.
1095
+ * 1b. Under relaxedLambdaSyntax: the next token is on the same line and the enclosing region is not `(...)`.
1096
+ * In this case the parsing function parses an Expr in location Location.InColonArg
1097
+ * enclosed in a SingleLineLambda region, and then eats the ENDlambda token
1098
+ * generated by the Scanner at the end of that region.
1099
+ * The reason for excluding (1b) in regions enclosed in parentheses is to avoid
1100
+ * an ambiguity with type ascription `(x: A => B)`, where function types are only
1101
+ * allowed inside parentheses.
1102
+ * 2. Under relaxedLambdaSyntax: the input starts with a `case`.
1101
1103
*/
1102
1104
def followingIsLambdaAfterColon (): Option [() => Tree ] =
1103
1105
val lookahead = in.LookaheadScanner (allowIndent = true )
@@ -1107,7 +1109,9 @@ object Parsers {
1107
1109
lookahead.observeArrowIndented()
1108
1110
if lookahead.token == INDENT || lookahead.token == EOF then
1109
1111
Some (() => expr(Location .InColonArg ))
1110
- else if ! in.currentRegion.isInstanceOf [InParens ] then
1112
+ else if in.featureEnabled(Feature .relaxedLambdaSyntax)
1113
+ && ! in.currentRegion.isInstanceOf [InParens ]
1114
+ then
1111
1115
Some : () =>
1112
1116
val t = inSepRegion(SingleLineLambda (_)):
1113
1117
expr(Location .InColonArg )
@@ -1122,7 +1126,7 @@ object Parsers {
1122
1126
else if lookahead.token == LPAREN || lookahead.token == LBRACKET then
1123
1127
lookahead.skipParens()
1124
1128
isArrowIndent()
1125
- else if lookahead.token == CASE then
1129
+ else if lookahead.token == CASE && in.featureEnabled( Feature .relaxedLambdaSyntax) then
1126
1130
Some (() => singleCaseMatch())
1127
1131
else
1128
1132
None
@@ -1193,9 +1197,11 @@ object Parsers {
1193
1197
/** Optionally, if we are seeing a lambda argument after a colon of the form
1194
1198
* : (params) =>
1195
1199
* body
1196
- * or a single-line lambda
1200
+ * or a single-line lambda (under relaxedLambdaSyntax)
1197
1201
* : (params) => body
1198
- * then return the function used to parse `body`.
1202
+ * or a case clause (under relaxedLambdaSyntax)
1203
+ * : case pat guard => rhs
1204
+ * then return the function used to parse `body` or the case clause.
1199
1205
*/
1200
1206
def detectColonLambda : Option [() => Tree ] =
1201
1207
if sourceVersion.enablesFewerBraces && in.token == COLONfollow
@@ -2432,7 +2438,7 @@ object Parsers {
2432
2438
val arrowOffset = accept(ARROW )
2433
2439
val body = expr(location)
2434
2440
makePolyFunction(tparams, body, " literal" , errorTermTree(arrowOffset), start, arrowOffset)
2435
- case CASE =>
2441
+ case CASE if in.featureEnabled( Feature .relaxedLambdaSyntax) =>
2436
2442
singleCaseMatch()
2437
2443
case _ =>
2438
2444
val saved = placeholderParams
0 commit comments