Skip to content

Commit 8698c50

Browse files
committed
Drop "given extension" syntax
1 parent 84a0197 commit 8698c50

File tree

3 files changed

+45
-62
lines changed

3 files changed

+45
-62
lines changed

compiler/src/dotty/tools/dotc/core/Flags.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ object Flags {
2222

2323
type Flag = opaques.Flag
2424

25-
given extension (x: FlagSet) with
25+
extension on (x: FlagSet) {
2626

2727
def bits: Long = opaques.toBits(x)
2828

@@ -150,7 +150,7 @@ object Flags {
150150

151151
/** The string representation of the given flag set */
152152
def flagsString: String = x.flagStrings("").mkString(" ")
153-
end given
153+
}
154154

155155
def termFlagSet(x: Long) = FlagSet(TERMS | x)
156156

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

Lines changed: 42 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3506,70 +3506,54 @@ object Parsers {
35063506
var mods1 = addMod(mods, instanceMod)
35073507
val hasGivenSig = followingIsGivenSig()
35083508
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
35143510

35153511
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
35443535
in.nextToken()
3536+
accept(SUBTYPE)
35453537
TypeBoundsTree(EmptyTree, toplevelTyp()) :: Nil
35463538
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)
35563540

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+
}
35733557
finalizeDef(gdef, mods1, start)
35743558
}
35753559

compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,10 +509,9 @@ class ExtractSemanticDB extends Phase with
509509
else limit
510510
Span(start max limit, end)
511511

512-
private given extension (span: Span) with
512+
private extension on (span: Span):
513513
def hasLength: Boolean = span.start != span.end
514514
def zeroLength: Boolean = span.start == span.end
515-
end given
516515

517516
/**Consume head while not an import statement.
518517
* Returns the rest of the list after the first import, or else the empty list

0 commit comments

Comments
 (0)