@@ -3549,7 +3549,7 @@ object Parsers {
3549
3549
syntaxError(i " extension clause can only define methods " , stat.span)
3550
3550
}
3551
3551
3552
- /** GivenDef ::= [GivenSig] (Type [‘=’ Expr] | StructuralInstance )
3552
+ /** GivenDef ::= [GivenSig] (Type [‘=’ Expr] | ConstrApps TemplateBody )
3553
3553
* GivenSig ::= [id] [DefTypeParamClause] {UsingParamClauses} ‘:’
3554
3554
*/
3555
3555
def givenDef (start : Offset , mods : Modifiers , givenMod : Mod ) = atSpan(start, nameStart) {
@@ -3567,10 +3567,9 @@ object Parsers {
3567
3567
newLinesOpt()
3568
3568
val noParams = tparams.isEmpty && vparamss.isEmpty
3569
3569
if ! (name.isEmpty && noParams) then accept(COLON )
3570
- val parents =
3571
- if isSimpleLiteral then toplevelTyp() :: Nil
3572
- else constrApp() :: withConstrApps()
3570
+ val parents = if isSimpleLiteral then toplevelTyp() :: Nil else constrApps()
3573
3571
val parentsIsType = parents.length == 1 && parents.head.isType
3572
+ newLineOptWhenFollowedBy(LBRACE )
3574
3573
if in.token == EQUALS && parentsIsType then
3575
3574
accept(EQUALS )
3576
3575
mods1 |= Final
@@ -3579,17 +3578,17 @@ object Parsers {
3579
3578
ValDef (name, parents.head, subExpr())
3580
3579
else
3581
3580
DefDef (name, joinParams(tparams, vparamss), parents.head, subExpr())
3582
- else if in.token != WITH && parentsIsType then
3583
- if name.isEmpty then
3584
- syntaxError(em " anonymous given cannot be abstract " )
3585
- DefDef (name, joinParams(tparams, vparamss), parents.head, EmptyTree )
3586
- else
3581
+ else if isTemplateBodyStart then
3587
3582
val tparams1 = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal ))
3588
3583
val vparamss1 = vparamss.map(_.map(vparam =>
3589
3584
vparam.withMods(vparam.mods &~ Param | ParamAccessor | Protected )))
3590
- val templ = withTemplate (makeConstructor(tparams1, vparamss1), parents)
3585
+ val templ = templateBodyOpt (makeConstructor(tparams1, vparamss1), parents, Nil )
3591
3586
if noParams then ModuleDef (name, templ)
3592
3587
else TypeDef (name.toTypeName, templ)
3588
+ else
3589
+ if name.isEmpty then
3590
+ syntaxError(em " anonymous given cannot be abstract " )
3591
+ DefDef (name, joinParams(tparams, vparamss), parents.head, EmptyTree )
3593
3592
end gdef
3594
3593
finalizeDef(gdef, mods1, start)
3595
3594
}
@@ -3779,14 +3778,6 @@ object Parsers {
3779
3778
vd
3780
3779
}
3781
3780
3782
- /** with Template, with EOL <indent> interpreted */
3783
- def withTemplate (constr : DefDef , parents : List [Tree ]): Template =
3784
- if in.token != WITH then syntaxError(em " `with` expected " )
3785
- possibleTemplateStart() // consumes a WITH token
3786
- val (self, stats) = templateBody()
3787
- Template (constr, parents, Nil , self, stats)
3788
- .withSpan(Span (constr.span.orElse(parents.head.span).start, in.lastOffset))
3789
-
3790
3781
/* -------- STATSEQS ------------------------------------------- */
3791
3782
3792
3783
/** Create a tree representing a packaging */
0 commit comments