@@ -1085,9 +1085,19 @@ object Parsers {
10851085 }
10861086
10871087 /** Is the token sequence following the current `:` token classified as a lambda?
1088- * This is the case if the input starts with an identifier, a wildcard, or
1089- * something enclosed in (...) or [...], and this is followed by a `=>` or `?=>`
1090- * and an INDENT.
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.
10911101 */
10921102 def followingIsLambdaAfterColon (): Option [() => Tree ] =
10931103 val lookahead = in.LookaheadScanner (allowIndent = true )
@@ -1101,7 +1111,7 @@ object Parsers {
11011111 Some : () =>
11021112 val t = inSepRegion(SingleLineLambda (_)):
11031113 expr(Location .InColonArg )
1104- accept(ENDLAMBDA )
1114+ accept(ENDlambda )
11051115 t
11061116 else None
11071117 else None
@@ -1178,11 +1188,14 @@ object Parsers {
11781188 case _ => infixOp
11791189 }
11801190
1181- /** True if we are seeing a lambda argument after a colon of the form:
1191+ /** Optionally, if we are seeing a lambda argument after a colon of the form
11821192 * : (params) =>
11831193 * body
1194+ * or a single-line lambda
1195+ * : (params) => body
1196+ * then return the function used to parse `body`.
11841197 */
1185- def isColonLambda : Option [() => Tree ] =
1198+ def detectColonLambda : Option [() => Tree ] =
11861199 if sourceVersion.enablesFewerBraces && in.token == COLONfollow
11871200 then followingIsLambdaAfterColon()
11881201 else None
@@ -1209,7 +1222,7 @@ object Parsers {
12091222 opStack = OpInfo (top1, op, in.offset) :: opStack
12101223 colonAtEOLOpt()
12111224 newLineOptWhenFollowing(canStartOperand)
1212- isColonLambda match
1225+ detectColonLambda match
12131226 case Some (parseExpr) =>
12141227 in.nextToken()
12151228 recur(parseExpr())
@@ -2778,6 +2791,7 @@ object Parsers {
27782791 * | SimpleExpr1 ColonArgument
27792792 * ColonArgument ::= colon [LambdaStart]
27802793 * indent (CaseClauses | Block) outdent
2794+ * | colon LambdaStart expr ENDlambda -- under experimental.relaxedLambdaSyntax
27812795 * LambdaStart ::= FunParams (‘=>’ | ‘?=>’)
27822796 * | TypTypeParamClause ‘=>’
27832797 * ColonArgBody ::= indent (CaseClauses | Block) outdent
@@ -2860,7 +2874,7 @@ object Parsers {
28602874 makeParameter(name.asTermName, typedOpt(), Modifiers (), isBackquoted = isBackquoted(id))
28612875 }
28622876 case _ => t
2863- else isColonLambda match
2877+ else detectColonLambda match
28642878 case Some (parseExpr) =>
28652879 val app =
28662880 atSpan(startOffset(t), in.skipToken()):
0 commit comments