Skip to content

Commit a57134e

Browse files
committed
Enable closure arguments only under fewerBracesEnabled
1 parent dbfde1c commit a57134e

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2204,7 +2204,7 @@ object Parsers {
22042204
* | SimpleExpr `.` MatchClause
22052205
* | SimpleExpr (TypeArgs | NamedTypeArgs)
22062206
* | SimpleExpr1 ArgumentExprs
2207-
* | SimpleExpr1 :<<< BlockExpr >>> -- under language.experimental.fewerBraces
2207+
* | SimpleExpr1 :<<< (CaseClauses | Block) >>> -- under language.experimental.fewerBraces
22082208
* | SimpleExpr1 FunParams (‘=>’ | ‘?=>’) indent Block outdent -- under language.experimental.fewerBraces
22092209
* Quoted ::= ‘'’ ‘{’ Block ‘}’
22102210
* | ‘'’ ‘[’ Type ‘]’
@@ -2265,11 +2265,10 @@ object Parsers {
22652265
case LBRACKET =>
22662266
val tapp = atSpan(startOffset(t), in.offset) { TypeApply(t, typeArgs(namedOK = true, wildOK = false)) }
22672267
simpleExprRest(tapp, location, canApply = true)
2268-
case LPAREN | LBRACE | INDENT if canApply =>
2269-
val inParents = in.token == LPAREN
2268+
case LPAREN if canApply =>
22702269
val app = atSpan(startOffset(t), in.offset) {
22712270
val argExprs @ (args, isUsing) = argumentExprs()
2272-
if inParents && !isUsing && in.isArrow && location != Location.InGuard then
2271+
if !isUsing && in.isArrow && location != Location.InGuard && in.fewerBracesEnabled then
22732272
val params = convertToParams(Tuple(args))
22742273
if params.forall(_.name != nme.ERROR) then
22752274
applyToClosure(t, in.offset, params)
@@ -2279,13 +2278,17 @@ object Parsers {
22792278
mkApply(t, argExprs)
22802279
}
22812280
simpleExprRest(app, location, canApply = true)
2281+
case LBRACE | INDENT if canApply =>
2282+
val app = atSpan(startOffset(t), in.offset) { mkApply(t, argumentExprs()) }
2283+
simpleExprRest(app, location, canApply = true)
22822284
case USCORE =>
2283-
if in.lookahead.isArrow && location != Location.InGuard then
2285+
if in.lookahead.isArrow && location != Location.InGuard && in.fewerBracesEnabled then
22842286
val app = applyToClosure(t, in.offset, convertToParams(wildcardIdent()))
22852287
simpleExprRest(app, location, canApply = true)
22862288
else
22872289
atSpan(startOffset(t), in.skipToken()) { PostfixOp(t, Ident(nme.WILDCARD)) }
2288-
case IDENTIFIER if !in.isOperator && in.lookahead.isArrow && location != Location.InGuard =>
2290+
case IDENTIFIER
2291+
if !in.isOperator && in.lookahead.isArrow && location != Location.InGuard && in.fewerBracesEnabled =>
22892292
val app = applyToClosure(t, in.offset, convertToParams(termIdent()))
22902293
simpleExprRest(app, location, canApply = true)
22912294
case _ =>

docs/docs/internals/syntax.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ SimpleExpr ::= SimpleRef
244244
| SimpleExpr ‘.’ MatchClause
245245
| SimpleExpr TypeArgs TypeApply(expr, args)
246246
| SimpleExpr ArgumentExprs Apply(expr, args)
247-
| SimpleExpr1 :<<< BlockExpr >>> -- under language.experimental.fewerBraces
247+
| SimpleExpr1 :<<< (CaseClauses | Block) >>> -- under language.experimental.fewerBraces
248248
| SimpleExpr1 FunParams (‘=>’ | ‘?=>’) indent Block outdent -- under language.experimental.fewerBraces
249249
| SimpleExpr ‘_’ PostfixOp(expr, _) (to be dropped)
250250
| XmlExpr -- to be dropped

tests/neg/closure-args.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import language.experimental.fewerBraces
2+
13
val x = List().map (x: => Int) => // error
24
???
35
val y = List() map x => // error

tests/neg/i7751.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
import language.experimental.fewerBraces
12
val a = Some(a=a,)=> // error // error // error
23
val a = Some(x=y,)=>

tests/pos/closure-args.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import language.experimental.fewerBraces
2+
13
val xs = List(1, 2, 3)
24
val ys = xs.map x =>
35
x + 1

0 commit comments

Comments
 (0)