@@ -368,9 +368,9 @@ object Parsers {
368
368
}
369
369
370
370
private [this ] var inEnum = false
371
- private def withinEnum [T ](isEnum : Boolean )( body : => T ): T = {
371
+ private def withinEnum [T ](body : => T ): T = {
372
372
val saved = inEnum
373
- inEnum = isEnum
373
+ inEnum = true
374
374
try body
375
375
finally inEnum = saved
376
376
}
@@ -1586,7 +1586,7 @@ object Parsers {
1586
1586
case parent :: Nil if in.token != LBRACE =>
1587
1587
reposition(if (parent.isType) ensureApplied(wrapNew(parent)) else parent)
1588
1588
case _ =>
1589
- New (reposition(templateBodyOpt(emptyConstructor, parents, Nil , isEnum = false )))
1589
+ New (reposition(templateBodyOpt(emptyConstructor, parents, Nil )))
1590
1590
}
1591
1591
}
1592
1592
@@ -2555,12 +2555,7 @@ object Parsers {
2555
2555
val modName = ident()
2556
2556
val clsName = modName.toTypeName
2557
2557
val constr = classConstr()
2558
- val templ = templateOpt(constr, isEnum = true )
2559
- templ match {
2560
- case Template (_, _, _, List (EmptyTree )) =>
2561
- syntaxError(" enum body should not be empty." , start)
2562
- case _ =>
2563
- }
2558
+ val templ = template(constr, isEnum = true )
2564
2559
finalizeDef(TypeDef (clsName, templ), addMod(mods, enumMod), start)
2565
2560
}
2566
2561
@@ -2633,7 +2628,7 @@ object Parsers {
2633
2628
val tparams1 = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal ))
2634
2629
val vparamss1 = vparamss.map(_.map(vparam =>
2635
2630
vparam.withMods(vparam.mods &~ Param | ParamAccessor | PrivateLocal )))
2636
- val templ = templateBodyOpt(makeConstructor(tparams1, vparamss1), parents, Nil , isEnum = false )
2631
+ val templ = templateBodyOpt(makeConstructor(tparams1, vparamss1), parents, Nil )
2637
2632
if (tparams.isEmpty && vparamss.isEmpty) ModuleDef (name, templ)
2638
2633
else TypeDef (name.toTypeName, templ)
2639
2634
}
@@ -2696,26 +2691,28 @@ object Parsers {
2696
2691
def template (constr : DefDef , isEnum : Boolean = false ): Template = {
2697
2692
val (parents, derived) = inheritClauses()
2698
2693
newLineOptWhenFollowedBy(LBRACE )
2699
- if (isEnum && in.token != LBRACE )
2700
- syntaxErrorOrIncomplete(ExpectedTokenButFound (LBRACE , in.token))
2701
- templateBodyOpt(constr, parents, derived, isEnum)
2694
+ if (isEnum) {
2695
+ val (self, stats) = withinEnum(templateBody())
2696
+ Template (constr, parents, derived, self, stats)
2697
+ }
2698
+ else templateBodyOpt(constr, parents, derived)
2702
2699
}
2703
2700
2704
2701
/** TemplateOpt = [Template]
2705
2702
*/
2706
- def templateOpt (constr : DefDef , isEnum : Boolean = false ): Template = {
2703
+ def templateOpt (constr : DefDef ): Template = {
2707
2704
newLineOptWhenFollowedBy(LBRACE )
2708
2705
if (in.token == EXTENDS || isIdent(nme.derives ) || in.token == LBRACE )
2709
- template(constr, isEnum )
2706
+ template(constr)
2710
2707
else
2711
2708
Template (constr, Nil , Nil , EmptyValDef , Nil )
2712
2709
}
2713
2710
2714
2711
/** TemplateBody ::= [nl] `{' TemplateStatSeq `}'
2715
2712
*/
2716
- def templateBodyOpt (constr : DefDef , parents : List [Tree ], derived : List [Tree ], isEnum : Boolean ): Template = {
2713
+ def templateBodyOpt (constr : DefDef , parents : List [Tree ], derived : List [Tree ]): Template = {
2717
2714
val (self, stats) =
2718
- if (in.token == LBRACE ) withinEnum(isEnum)( templateBody() ) else (EmptyValDef , Nil )
2715
+ if (in.token == LBRACE ) templateBody() else (EmptyValDef , Nil )
2719
2716
Template (constr, parents, derived, self, stats)
2720
2717
}
2721
2718
0 commit comments