@@ -1178,6 +1178,11 @@ object Parsers {
11781178 newLineOptWhenFollowedBy(LBRACE )
11791179 }
11801180
1181+ def possibleTemplateStart (): Unit = {
1182+ in.observeIndented()
1183+ newLineOptWhenFollowedBy(LBRACE )
1184+ }
1185+
11811186 def indentRegion [T ](tag : EndMarkerTag )(op : => T ): T = {
11821187 val iw = in.currentRegion.indentWidth
11831188 val t = op
@@ -3330,7 +3335,7 @@ object Parsers {
33303335 if (in.token == LPAREN )
33313336 try paramClause(prefix = true ) :: Nil
33323337 finally {
3333- possibleBracesStart ()
3338+ possibleTemplateStart ()
33343339 if (! in.isNestedStart) syntaxErrorOrIncomplete(" `{' expected" )
33353340 }
33363341 else Nil
@@ -3348,7 +3353,7 @@ object Parsers {
33483353 DefDef (name, tparams, vparamss, parents.head, expr())
33493354 }
33503355 else {
3351- possibleBracesStart ()
3356+ possibleTemplateStart ()
33523357 val (tparams1, vparamss1) =
33533358 if (leadingParamss.nonEmpty)
33543359 (tparams, leadingParamss)
@@ -3448,7 +3453,7 @@ object Parsers {
34483453 */
34493454 def template (constr : DefDef , isEnum : Boolean = false ): Template = {
34503455 val (parents, derived) = inheritClauses()
3451- possibleBracesStart ()
3456+ possibleTemplateStart ()
34523457 if (isEnum) {
34533458 val (self, stats) = withinEnum(templateBody())
34543459 Template (constr, parents, derived, self, stats)
@@ -3458,13 +3463,15 @@ object Parsers {
34583463
34593464 /** TemplateOpt = [Template]
34603465 */
3461- def templateOpt (constr : DefDef ): Template = {
3466+ def templateOpt (constr : DefDef ): Template =
34623467 possibleBracesStart()
3463- if (in.token == EXTENDS || isIdent(nme.derives ) || in.isNestedStart )
3468+ if (in.token == EXTENDS || isIdent(nme.derives ))
34643469 template(constr)
3465- else
3466- Template (constr, Nil , Nil , EmptyValDef , Nil )
3467- }
3470+ else {
3471+ possibleTemplateStart()
3472+ if (in.isNestedStart) template(constr)
3473+ else Template (constr, Nil , Nil , EmptyValDef , Nil )
3474+ }
34683475
34693476 /** TemplateBody ::= [nl] `{' TemplateStatSeq `}'
34703477 */
@@ -3496,7 +3503,7 @@ object Parsers {
34963503 def packaging (start : Int ): Tree = {
34973504 val pkg = qualId()
34983505 indentRegion(pkg) {
3499- possibleBracesStart ()
3506+ possibleTemplateStart ()
35003507 val stats = inDefScopeBraces(topStatSeq())
35013508 makePackaging(start, pkg, stats)
35023509 }
@@ -3702,7 +3709,7 @@ object Parsers {
37023709 else {
37033710 val pkg = qualId()
37043711 indentRegion(pkg) {
3705- possibleBracesStart ()
3712+ possibleTemplateStart ()
37063713 if (in.token == EOF )
37073714 ts += makePackaging(start, pkg, List ())
37083715 else if (in.isNestedStart) {
0 commit comments