@@ -3506,70 +3506,54 @@ object Parsers {
3506
3506
var mods1 = addMod(mods, instanceMod)
3507
3507
val hasGivenSig = followingIsGivenSig()
3508
3508
val nameStart = in.offset
3509
- val (name, isOldExtension) =
3510
- if isIdent && hasGivenSig then
3511
- (ident(), in.token == COLON && in.lookaheadIn(nme.extension))
3512
- else
3513
- (EmptyTermName , isIdent(nme.extension))
3509
+ val name = if isIdent && hasGivenSig then ident() else EmptyTermName
3514
3510
3515
3511
val gdef = in.endMarkerScope(if name.isEmpty then GIVEN else name) {
3516
- if isOldExtension then
3517
- if (in.token == COLON ) in.nextToken()
3518
- assert(ident() == nme.extension)
3519
- val tparams = typeParamClauseOpt(ParamOwner .Def )
3520
- val extParams = paramClause(0 , prefix = true )
3521
- val givenParamss = paramClauses(givenOnly = true )
3522
- possibleTemplateStart()
3523
- val templ = templateBodyOpt(
3524
- makeConstructor(tparams, extParams :: givenParamss), Nil , Nil )
3525
- templ.body.foreach(checkExtensionMethod(tparams, _))
3526
- ModuleDef (name, templ)
3527
- else
3528
- val hasLabel = ! name.isEmpty && in.token == COLON || isIdent(nme.as)
3529
- if hasLabel then in.nextToken()
3530
- val tparams = typeParamClauseOpt(ParamOwner .Def )
3531
- val paramsStart = in.offset
3532
- val vparamss =
3533
- if in.token == LPAREN && followingIsParamOrGivenType()
3534
- then paramClauses()
3535
- else Nil
3536
- def checkAllGivens (vparamss : List [List [ValDef ]], what : String ) =
3537
- vparamss.foreach(_.foreach(vparam =>
3538
- if ! vparam.mods.is(Given ) then syntaxError(em " $what must be preceded by `using` " , vparam.span)))
3539
- checkAllGivens(vparamss, " parameter of given instance" )
3540
- val parents =
3541
- if in.token == SUBTYPE && ! hasLabel then
3542
- if ! mods.is(Inline ) then
3543
- syntaxError(" `<:` is only allowed for given with `inline` modifier" )
3512
+ val hasLabel = ! name.isEmpty && in.token == COLON || isIdent(nme.as)
3513
+ if hasLabel then in.nextToken()
3514
+ val tparams = typeParamClauseOpt(ParamOwner .Def )
3515
+ val paramsStart = in.offset
3516
+ val vparamss =
3517
+ if in.token == LPAREN && followingIsParamOrGivenType()
3518
+ then paramClauses()
3519
+ else Nil
3520
+ def checkAllGivens (vparamss : List [List [ValDef ]], what : String ) =
3521
+ vparamss.foreach(_.foreach(vparam =>
3522
+ if ! vparam.mods.is(Given ) then syntaxError(em " $what must be preceded by `using` " , vparam.span)))
3523
+ checkAllGivens(vparamss, " parameter of given instance" )
3524
+ val parents =
3525
+ if in.token == SUBTYPE && ! hasLabel then
3526
+ if ! mods.is(Inline ) then
3527
+ syntaxError(" `<:` is only allowed for given with `inline` modifier" )
3528
+ in.nextToken()
3529
+ TypeBoundsTree (EmptyTree , toplevelTyp()) :: Nil
3530
+ else
3531
+ if ! hasLabel && ! (name.isEmpty && tparams.isEmpty && vparamss.isEmpty) then
3532
+ if in.token == COLON then in.nextToken()
3533
+ else accept(nme.as)
3534
+ if in.token == USCORE then
3544
3535
in.nextToken()
3536
+ accept(SUBTYPE )
3545
3537
TypeBoundsTree (EmptyTree , toplevelTyp()) :: Nil
3546
3538
else
3547
- if ! hasLabel && ! (name.isEmpty && tparams.isEmpty && vparamss.isEmpty) then
3548
- if in.token == COLON then in.nextToken()
3549
- else accept(nme.as)
3550
- if in.token == USCORE then
3551
- in.nextToken()
3552
- accept(SUBTYPE )
3553
- TypeBoundsTree (EmptyTree , toplevelTyp()) :: Nil
3554
- else
3555
- constrApps(commaOK = true , templateCanFollow = true )
3539
+ constrApps(commaOK = true , templateCanFollow = true )
3556
3540
3557
- if in.token == EQUALS && parents.length == 1 && parents.head.isType then
3558
- in.nextToken()
3559
- mods1 |= Final
3560
- DefDef (name, tparams, vparamss, parents.head, subExpr())
3561
- else
3562
- parents match
3563
- case (_ : TypeBoundsTree ) :: _ => syntaxError(" `=` expected" )
3564
- case _ =>
3565
- possibleTemplateStart()
3566
- val tparams1 = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal ))
3567
- val vparamss1 = vparamss.map(_.map(vparam =>
3568
- vparam.withMods(vparam.mods &~ Param | ParamAccessor | PrivateLocal )))
3569
- val templ = templateBodyOpt(makeConstructor(tparams1, vparamss1), parents, Nil )
3570
- if tparams.isEmpty && vparamss.isEmpty then ModuleDef (name, templ)
3571
- else TypeDef (name.toTypeName, templ)
3572
- }
3541
+ if in.token == EQUALS && parents.length == 1 && parents.head.isType then
3542
+ in.nextToken()
3543
+ mods1 |= Final
3544
+ DefDef (name, tparams, vparamss, parents.head, subExpr())
3545
+ else
3546
+ parents match
3547
+ case (_ : TypeBoundsTree ) :: _ => syntaxError(" `=` expected" )
3548
+ case _ =>
3549
+ possibleTemplateStart()
3550
+ val tparams1 = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal ))
3551
+ val vparamss1 = vparamss.map(_.map(vparam =>
3552
+ vparam.withMods(vparam.mods &~ Param | ParamAccessor | PrivateLocal )))
3553
+ val templ = templateBodyOpt(makeConstructor(tparams1, vparamss1), parents, Nil )
3554
+ if tparams.isEmpty && vparamss.isEmpty then ModuleDef (name, templ)
3555
+ else TypeDef (name.toTypeName, templ)
3556
+ }
3573
3557
finalizeDef(gdef, mods1, start)
3574
3558
}
3575
3559
0 commit comments