@@ -1276,10 +1276,17 @@ object Parsers {
1276
1276
if (in.token == COLONEOL ) in.nextToken()
1277
1277
}
1278
1278
1279
- def possibleBracesStart (): Unit = {
1279
+ def argumentStart (): Unit =
1280
1280
colonAtEOLOpt()
1281
- newLineOptWhenFollowedBy(LBRACE )
1282
- }
1281
+ if migrateTo3 && in.token == NEWLINE && in.next.token == LBRACE then
1282
+ in.nextToken()
1283
+ if in.indentWidth(in.offset) == in.currentRegion.indentWidth then
1284
+ ctx.errorOrMigrationWarning(
1285
+ i """ This opening brace will start a new statement in Scala 3.
1286
+ |It needs to be indented to the right to keep being treated as
1287
+ |an argument to the previous expression. ${rewriteNotice()}""" ,
1288
+ in.sourcePos())
1289
+ patch(source, Span (in.offset), " " )
1283
1290
1284
1291
def possibleTemplateStart (isNew : Boolean = false ): Unit =
1285
1292
in.observeColonEOL()
@@ -1509,7 +1516,7 @@ object Parsers {
1509
1516
val refinedType : () => Tree = () => refinedTypeRest(withType())
1510
1517
1511
1518
def refinedTypeRest (t : Tree ): Tree = {
1512
- possibleBracesStart ()
1519
+ argumentStart ()
1513
1520
if (in.isNestedStart)
1514
1521
refinedTypeRest(atSpan(startOffset(t)) { RefinedTypeTree (rejectWildcardType(t), refinement()) })
1515
1522
else t
@@ -2265,7 +2272,7 @@ object Parsers {
2265
2272
}
2266
2273
2267
2274
def simpleExprRest (t : Tree , canApply : Boolean = true ): Tree = {
2268
- if (canApply) possibleBracesStart ()
2275
+ if (canApply) argumentStart ()
2269
2276
in.token match {
2270
2277
case DOT =>
2271
2278
in.nextToken()
@@ -2338,7 +2345,7 @@ object Parsers {
2338
2345
/** ArgumentExprss ::= {ArgumentExprs}
2339
2346
*/
2340
2347
def argumentExprss (fn : Tree ): Tree = {
2341
- possibleBracesStart ()
2348
+ argumentStart ()
2342
2349
if (in.token == LPAREN || in.isNestedStart) argumentExprss(mkApply(fn, argumentExprs()))
2343
2350
else fn
2344
2351
}
@@ -2831,7 +2838,7 @@ object Parsers {
2831
2838
}
2832
2839
2833
2840
def annotations (skipNewLines : Boolean = false ): List [Tree ] = {
2834
- if (skipNewLines) newLineOptWhenFollowedBy (AT )
2841
+ if (skipNewLines) newLinesOptWhenFollowedBy (AT )
2835
2842
if (in.token == AT ) annot() :: annotations(skipNewLines)
2836
2843
else Nil
2837
2844
}
@@ -3358,7 +3365,7 @@ object Parsers {
3358
3365
*/
3359
3366
def selfInvocation (): Tree =
3360
3367
atSpan(accept(THIS )) {
3361
- possibleBracesStart ()
3368
+ argumentStart ()
3362
3369
argumentExprss(mkApply(Ident (nme.CONSTRUCTOR ), argumentExprs()))
3363
3370
}
3364
3371
0 commit comments