Skip to content

Commit 2dba45c

Browse files
Merge pull request #8270 from dotty-staging/change-given-using-2
Drop given parameter syntax
2 parents 6a949f2 + d008b78 commit 2dba45c

File tree

47 files changed

+133
-178
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+133
-178
lines changed

community-build/test/scala/dotty/communitybuild/CommunityBuildTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ sealed trait CommunityProject:
4747
/** Is this project running in the test or update mode in the
4848
* context of the given suite? @see `run` for more details.
4949
*/
50-
final def isUpdateMode(given suite: CommunityBuildTest) =
50+
final def isUpdateMode(using suite: CommunityBuildTest) =
5151
suite.isInstanceOf[CommunityBuildUpdate]
5252

5353
/** Depending on the mode of operation, either
@@ -60,7 +60,7 @@ sealed trait CommunityProject:
6060
* and avoid network overhead. See https://github.com/lampepfl/dotty-drone
6161
* for more infrastructural details.
6262
*/
63-
final def run()(given suite: CommunityBuildTest) =
63+
final def run()(using suite: CommunityBuildTest) =
6464
val runCmd = if isUpdateMode then updateCommand else testCommand
6565
if !isUpdateMode then dependencies.foreach(_.publish())
6666
suite.test(project, binaryName, runCommandsArgs :+ runCmd)

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: 46 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ object Parsers {
917917
def followingIsParamOrGivenType() =
918918
val lookahead = in.LookaheadScanner()
919919
lookahead.nextToken()
920-
if startParamOrGivenTypeTokens.contains(lookahead.token)
920+
if startParamTokens.contains(lookahead.token)
921921
|| lookahead.isIdent(nme.using)
922922
then true
923923
else if lookahead.token == IDENTIFIER then
@@ -1450,8 +1450,6 @@ object Parsers {
14501450
case MATCH => matchType(t)
14511451
case FORSOME => syntaxError(ExistentialTypesNoLongerSupported()); t
14521452
case _ =>
1453-
if (imods.isOneOf(GivenOrImplicit) && !t.isInstanceOf[FunctionWithMods])
1454-
syntaxError(ImplicitTypesCanOnlyBeFunctionTypes(), implicitKwPos(start))
14551453
if (imods.is(Erased) && !t.isInstanceOf[FunctionWithMods])
14561454
syntaxError(ErasedTypesCanOnlyBeFunctionTypes(), implicitKwPos(start))
14571455
t
@@ -2299,7 +2297,7 @@ object Parsers {
22992297
def parArgumentExprs(): (List[Tree], Boolean) = inParens {
23002298
if in.token == RPAREN then
23012299
(Nil, false)
2302-
else if in.token == GIVEN || isIdent(nme.using) then
2300+
else if isIdent(nme.using) then
23032301
in.nextToken()
23042302
(commaSeparated(argumentExpr), true)
23052303
else
@@ -2786,7 +2784,7 @@ object Parsers {
27862784
normalize(loop(start))
27872785
}
27882786

2789-
val funTypeArgMods: BitSet = BitSet(GIVEN, ERASED)
2787+
val funTypeArgMods: BitSet = BitSet(ERASED)
27902788

27912789
/** Wrap annotation or constructor in New(...).<init> */
27922790
def wrapNew(tpt: Tree): Select = Select(New(tpt), nme.CONSTRUCTOR)
@@ -2912,7 +2910,7 @@ object Parsers {
29122910
def paramMods() =
29132911
if in.token == IMPLICIT then addParamMod(() => Mod.Implicit())
29142912
else
2915-
if in.token == GIVEN || isIdent(nme.using) then addParamMod(() => Mod.Given())
2913+
if isIdent(nme.using) then addParamMod(() => Mod.Given())
29162914
if in.token == ERASED then addParamMod(() => Mod.Erased())
29172915

29182916
def param(): ValDef = {
@@ -3508,70 +3506,54 @@ object Parsers {
35083506
var mods1 = addMod(mods, instanceMod)
35093507
val hasGivenSig = followingIsGivenSig()
35103508
val nameStart = in.offset
3511-
val (name, isOldExtension) =
3512-
if isIdent && hasGivenSig then
3513-
(ident(), in.token == COLON && in.lookaheadIn(nme.extension))
3514-
else
3515-
(EmptyTermName, isIdent(nme.extension))
3509+
val name = if isIdent && hasGivenSig then ident() else EmptyTermName
35163510

35173511
val gdef = in.endMarkerScope(if name.isEmpty then GIVEN else name) {
3518-
if isOldExtension then
3519-
if (in.token == COLON) in.nextToken()
3520-
assert(ident() == nme.extension)
3521-
val tparams = typeParamClauseOpt(ParamOwner.Def)
3522-
val extParams = paramClause(0, prefix = true)
3523-
val givenParamss = paramClauses(givenOnly = true)
3524-
possibleTemplateStart()
3525-
val templ = templateBodyOpt(
3526-
makeConstructor(tparams, extParams :: givenParamss), Nil, Nil)
3527-
templ.body.foreach(checkExtensionMethod(tparams, _))
3528-
ModuleDef(name, templ)
3529-
else
3530-
val hasLabel = !name.isEmpty && in.token == COLON || isIdent(nme.as)
3531-
if hasLabel then in.nextToken()
3532-
val tparams = typeParamClauseOpt(ParamOwner.Def)
3533-
val paramsStart = in.offset
3534-
val vparamss =
3535-
if in.token == LPAREN && followingIsParamOrGivenType()
3536-
then paramClauses()
3537-
else Nil
3538-
def checkAllGivens(vparamss: List[List[ValDef]], what: String) =
3539-
vparamss.foreach(_.foreach(vparam =>
3540-
if !vparam.mods.is(Given) then syntaxError(em"$what must be preceded by `using`", vparam.span)))
3541-
checkAllGivens(vparamss, "parameter of given instance")
3542-
val parents =
3543-
if in.token == SUBTYPE && !hasLabel then
3544-
if !mods.is(Inline) then
3545-
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
35463535
in.nextToken()
3536+
accept(SUBTYPE)
35473537
TypeBoundsTree(EmptyTree, toplevelTyp()) :: Nil
35483538
else
3549-
if !hasLabel && !(name.isEmpty && tparams.isEmpty && vparamss.isEmpty) then
3550-
if in.token == COLON then in.nextToken()
3551-
else accept(nme.as)
3552-
if in.token == USCORE then
3553-
in.nextToken()
3554-
accept(SUBTYPE)
3555-
TypeBoundsTree(EmptyTree, toplevelTyp()) :: Nil
3556-
else
3557-
constrApps(commaOK = true, templateCanFollow = true)
3539+
constrApps(commaOK = true, templateCanFollow = true)
35583540

3559-
if in.token == EQUALS && parents.length == 1 && parents.head.isType then
3560-
in.nextToken()
3561-
mods1 |= Final
3562-
DefDef(name, tparams, vparamss, parents.head, subExpr())
3563-
else
3564-
parents match
3565-
case (_: TypeBoundsTree) :: _ => syntaxError("`=` expected")
3566-
case _ =>
3567-
possibleTemplateStart()
3568-
val tparams1 = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal))
3569-
val vparamss1 = vparamss.map(_.map(vparam =>
3570-
vparam.withMods(vparam.mods &~ Param | ParamAccessor | PrivateLocal)))
3571-
val templ = templateBodyOpt(makeConstructor(tparams1, vparamss1), parents, Nil)
3572-
if tparams.isEmpty && vparamss.isEmpty then ModuleDef(name, templ)
3573-
else TypeDef(name.toTypeName, templ)
3574-
}
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+
}
35753557
finalizeDef(gdef, mods1, start)
35763558
}
35773559

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ object Tokens extends TokensCommon {
257257
AT, CASE)
258258

259259
final val canEndStatTokens: TokenSet = atomicExprTokens | BitSet(
260-
TYPE, GIVEN, RPAREN, RBRACE, RBRACKET, OUTDENT)
260+
TYPE, GIVEN, RPAREN, RBRACE, RBRACKET, OUTDENT) // TODO: remove GIVEN once old import syntax is dropped
261261

262262
/** Tokens that stop a lookahead scan search for a `<-`, `then`, or `do`.
263263
* Used for disambiguating between old and new syntax.
@@ -280,12 +280,6 @@ object Tokens extends TokensCommon {
280280
*/
281281
final val startParamTokens: BitSet = modifierTokens | BitSet(VAL, VAR, AT)
282282

283-
/** Faced with the choice of a type `(...)` or a parameter or given type list
284-
* in `(...)`, the following tokens after the opening `(` determine it's
285-
* a parameter or given type list.
286-
*/
287-
final val startParamOrGivenTypeTokens: BitSet = startParamTokens | BitSet(GIVEN, ERASED)
288-
289283
final val scala3keywords = BitSet(ENUM, ERASED, GIVEN)
290284

291285
final val softModifierNames = Set(nme.inline, nme.opaque, nme.open)

0 commit comments

Comments
 (0)