@@ -1086,18 +1086,20 @@ object Parsers {
10861086
10871087 /** Is the token sequence following the current `:` token classified as a lambda?
10881088 * 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`.
11011103 */
11021104 def followingIsLambdaAfterColon (): Option [() => Tree ] =
11031105 val lookahead = in.LookaheadScanner (allowIndent = true )
@@ -1107,7 +1109,9 @@ object Parsers {
11071109 lookahead.observeArrowIndented()
11081110 if lookahead.token == INDENT || lookahead.token == EOF then
11091111 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
11111115 Some : () =>
11121116 val t = inSepRegion(SingleLineLambda (_)):
11131117 expr(Location .InColonArg )
@@ -1122,7 +1126,7 @@ object Parsers {
11221126 else if lookahead.token == LPAREN || lookahead.token == LBRACKET then
11231127 lookahead.skipParens()
11241128 isArrowIndent()
1125- else if lookahead.token == CASE then
1129+ else if lookahead.token == CASE && in.featureEnabled( Feature .relaxedLambdaSyntax) then
11261130 Some (() => singleCaseMatch())
11271131 else
11281132 None
@@ -1193,9 +1197,11 @@ object Parsers {
11931197 /** Optionally, if we are seeing a lambda argument after a colon of the form
11941198 * : (params) =>
11951199 * body
1196- * or a single-line lambda
1200+ * or a single-line lambda (under relaxedLambdaSyntax)
11971201 * : (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.
11991205 */
12001206 def detectColonLambda : Option [() => Tree ] =
12011207 if sourceVersion.enablesFewerBraces && in.token == COLONfollow
@@ -2432,7 +2438,7 @@ object Parsers {
24322438 val arrowOffset = accept(ARROW )
24332439 val body = expr(location)
24342440 makePolyFunction(tparams, body, " literal" , errorTermTree(arrowOffset), start, arrowOffset)
2435- case CASE =>
2441+ case CASE if in.featureEnabled( Feature .relaxedLambdaSyntax) =>
24362442 singleCaseMatch()
24372443 case _ =>
24382444 val saved = placeholderParams
0 commit comments