Skip to content

Commit a185a9e

Browse files
committed
Factor out parsing that's only relevant if there is a given sig
1 parent 79cca7b commit a185a9e

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3568,26 +3568,26 @@ object Parsers {
35683568
*/
35693569
def givenDef(start: Offset, mods: Modifiers, givenMod: Mod) = atSpan(start, nameStart) {
35703570
var mods1 = addMod(mods, givenMod)
3571-
val hasGivenSig = followingIsGivenSig()
35723571
val nameStart = in.offset
3573-
val name = if isIdent && hasGivenSig then ident() else EmptyTermName
3574-
3575-
val gdef =
3572+
val (name, tparams, vparamss, parents) = if followingIsGivenSig() then
3573+
val name = if isIdent then ident() else EmptyTermName
35763574
val tparams = typeParamClauseOpt(ParamOwner.Def)
35773575
newLineOpt()
35783576
val vparamss =
35793577
if in.token == LPAREN && in.lookahead.isIdent(nme.using)
35803578
then paramClauses(givenOnly = true)
35813579
else Nil
35823580
newLinesOpt()
3583-
val noParams = tparams.isEmpty && vparamss.isEmpty
3584-
if !(name.isEmpty && noParams) then
3585-
accept(nme.as)
3581+
accept(nme.as)
35863582
val parents = constrApps(commaOK = true)
3583+
(name, tparams, vparamss, parents)
3584+
else
3585+
(EmptyTermName, Nil, Nil, constrApps(commaOK = true))
3586+
val gdef =
35873587
if in.token == EQUALS && parents.length == 1 && parents.head.isType then
35883588
accept(EQUALS)
35893589
mods1 |= Final
3590-
if noParams && !mods.is(Inline) then
3590+
if tparams.isEmpty && vparamss.isEmpty && !mods.is(Inline) then
35913591
mods1 |= Lazy
35923592
ValDef(name, parents.head, subExpr())
35933593
else

0 commit comments

Comments
 (0)