Skip to content

Commit 101dbd6

Browse files
committed
Drop other aspects of old extension syntax
1 parent c4efe8a commit 101dbd6

16 files changed

+111
-151
lines changed

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

Lines changed: 22 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3362,27 +3362,6 @@ object Parsers {
33623362
Template(constr, parents, Nil, EmptyValDef, Nil)
33633363
}
33643364

3365-
/** Check that `vparamss` represents a legal collective parameter list for a given extension
3366-
*/
3367-
def checkExtensionParams(start: Offset, vparamss: List[List[ValDef]]): Unit = vparamss match
3368-
case (vparam :: Nil) :: vparamss1 if !vparam.mods.is(Given) =>
3369-
vparamss1.foreach(_.foreach(vparam =>
3370-
if !vparam.mods.is(Given) then
3371-
syntaxError(em"follow-on parameter in extension clause must be `given`", vparam.span)))
3372-
case _ =>
3373-
syntaxError(em"extension clause must start with a single regular parameter", start)
3374-
3375-
def checkExtensionMethod(tparams: List[Tree], stat: Tree): Unit = stat match {
3376-
case stat: DefDef =>
3377-
if stat.mods.is(Extension) then
3378-
syntaxError(i"no extension method allowed here since leading parameter was already given", stat.span)
3379-
else if tparams.nonEmpty && stat.tparams.nonEmpty then
3380-
syntaxError(i"extension method cannot have type parameters since some were already given previously",
3381-
stat.tparams.head.span)
3382-
case stat =>
3383-
syntaxError(i"extension clause can only define methods", stat.span)
3384-
}
3385-
33863365
/** GivenDef ::= [GivenSig (‘:’ | <:)] Type ‘=’ Expr
33873366
* | [GivenSig ‘:’] ConstrApps [[‘with’] TemplateBody]
33883367
* | [id ‘:’] ‘extension’ ExtParamClause {GivenParamClause} ExtMethods
@@ -3409,45 +3388,32 @@ object Parsers {
34093388
possibleTemplateStart()
34103389
val templ = templateBodyOpt(
34113390
makeConstructor(tparams, extParams :: givenParamss), Nil, Nil)
3412-
templ.body.foreach(checkExtensionMethod(tparams, _))
3391+
templ.body.foreach {
3392+
case stat: DefDef =>
3393+
if stat.mods.is(Extension) then
3394+
syntaxError(i"no extension method allowed here since leading parameter was already given", stat.span)
3395+
else if tparams.nonEmpty && stat.tparams.nonEmpty then
3396+
syntaxError(i"extension method cannot have type parameters since some were already given previously",
3397+
stat.tparams.head.span)
3398+
case stat =>
3399+
syntaxError(i"extension clause can only define methods", stat.span)
3400+
}
34133401
ModuleDef(name, templ)
34143402
else
3415-
var tparams: List[TypeDef] = Nil
3416-
var vparamss: List[List[ValDef]] = Nil
3417-
var hasExtensionParams = false
3418-
3419-
def parseParams(isExtension: Boolean): Unit =
3420-
if isExtension && (in.token == LBRACKET || in.token == LPAREN) then
3421-
hasExtensionParams = true
3422-
if tparams.nonEmpty || vparamss.nonEmpty then
3423-
syntaxError(i"cannot have parameters before and after `:` in extension")
3424-
if in.token == LBRACKET then
3425-
tparams = typeParamClause(ParamOwner.Def)
3403+
val tparams: List[TypeDef] = typeParamClauseOpt(ParamOwner.Def)
3404+
val vparamss: List[List[ValDef]] =
34263405
if in.token == LPAREN && followingIsParamOrGivenType() then
3427-
val paramsStart = in.offset
3428-
vparamss = paramClauses(givenOnly = !isExtension)
3429-
if isExtension then
3430-
checkExtensionParams(paramsStart, vparamss)
3431-
3432-
parseParams(isExtension = false)
3406+
paramClauses(givenOnly = true)
3407+
else Nil
34333408
val parents =
3434-
if in.token == COLON then
3435-
in.nextToken()
3436-
if in.token == LBRACKET
3437-
|| in.token == LPAREN && followingIsParamOrGivenType()
3438-
then
3439-
parseParams(isExtension = true)
3440-
Nil
3441-
else
3442-
constrApps(commaOK = true, templateCanFollow = true)
3443-
else if in.token == SUBTYPE then
3409+
if in.token == SUBTYPE then
34443410
if !mods.is(Inline) then
34453411
syntaxError("`<:' is only allowed for given with `inline' modifier")
34463412
in.nextToken()
34473413
TypeBoundsTree(EmptyTree, toplevelTyp()) :: Nil
3448-
else if name.isEmpty && !hasExtensionParams then
3414+
else
3415+
if in.token == COLON then in.nextToken()
34493416
constrApps(commaOK = true, templateCanFollow = true)
3450-
else Nil
34513417

34523418
if in.token == EQUALS && parents.length == 1 && parents.head.isType then
34533419
in.nextToken()
@@ -3458,17 +3424,11 @@ object Parsers {
34583424
case TypeBoundsTree(_, _) :: _ => syntaxError("`=' expected")
34593425
case _ =>
34603426
possibleTemplateStart()
3461-
if hasExtensionParams then
3462-
in.observeIndented()
3463-
else
3464-
tparams = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal))
3465-
vparamss = vparamss.map(_.map(vparam =>
3466-
vparam.withMods(vparam.mods &~ Param | ParamAccessor | PrivateLocal)))
3467-
val templ = templateBodyOpt(makeConstructor(tparams, vparamss), parents, Nil)
3468-
if hasExtensionParams then
3469-
templ.body.foreach(checkExtensionMethod(tparams, _))
3470-
ModuleDef(name, templ)
3471-
else if tparams.isEmpty && vparamss.isEmpty then ModuleDef(name, templ)
3427+
val tparams1 = tparams.map(tparam => tparam.withMods(tparam.mods | PrivateLocal))
3428+
val vparamss1 = vparamss.map(_.map(vparam =>
3429+
vparam.withMods(vparam.mods &~ Param | ParamAccessor | PrivateLocal)))
3430+
val templ = templateBodyOpt(makeConstructor(tparams1, vparamss1), parents, Nil)
3431+
if tparams.isEmpty && vparamss.isEmpty then ModuleDef(name, templ)
34723432
else TypeDef(name.toTypeName, templ)
34733433
}
34743434
finalizeDef(gdef, mods1, start)

library/src/scala/tasty/reflect/CommentOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package scala.tasty.reflect
22

33
trait CommentOps extends Core {
44

5-
given CommentOps: (self: Comment) {
5+
given CommentOps: extension (self: Comment) {
66

77
/** Raw comment string */
88
def raw: String = internal.Comment_raw(self)

library/src/scala/tasty/reflect/ConstantOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package reflect
33

44
trait ConstantOps extends Core {
55

6-
given ConstantOps: (const: Constant) {
6+
given ConstantOps: extension (const: Constant) {
77
def value: Any = internal.Constant_value(const)
88
}
99

library/src/scala/tasty/reflect/ContextOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package reflect
33

44
trait ContextOps extends Core {
55

6-
given ContextOps: (self: Context) {
6+
given ContextOps: extension (self: Context) {
77
/** Returns the owner of the context */
88
def owner: Symbol = internal.Context_owner(self)
99

library/src/scala/tasty/reflect/FlagsOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package scala.tasty.reflect
22

33
trait FlagsOps extends Core {
44

5-
given FlagsOps: (self: Flags) {
5+
given FlagsOps: extension (self: Flags) {
66

77
/** Is the given flag set a subset of this flag sets */
88
def is(that: Flags): Boolean = internal.Flags_is(self)(that)

library/src/scala/tasty/reflect/IdOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package reflect
33

44
trait IdOps extends Core {
55

6-
given IsOps: (id: Id) {
6+
given IdOps: extension (id: Id) {
77

88
/** Position in the source code */
99
def pos(given ctx: Context): Position = internal.Id_pos(id)

library/src/scala/tasty/reflect/ImplicitsOps.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ trait ImplicitsOps extends Core {
1111
@deprecated("Use _: ImplicitSearchSuccess", "")
1212
def unapply(isr: ImplicitSearchSuccess)(given ctx: Context): Option[ImplicitSearchSuccess] = Some(isr)
1313

14-
given SuccessOps: (self: ImplicitSearchSuccess) {
14+
given successOps: extension (self: ImplicitSearchSuccess) {
1515
def tree(given ctx: Context): Term = internal.ImplicitSearchSuccess_tree(self)
1616
}
1717

@@ -21,7 +21,7 @@ trait ImplicitsOps extends Core {
2121
@deprecated("Use _: ImplicitSearchFailure", "")
2222
def unapply(isr: ImplicitSearchFailure)(given ctx: Context): Option[ImplicitSearchFailure] = Some(isr)
2323

24-
given FailureOps: (self: ImplicitSearchFailure) {
24+
given failureOps: extension (self: ImplicitSearchFailure) {
2525
def explanation(given ctx: Context): String = internal.ImplicitSearchFailure_explanation(self)
2626
}
2727

library/src/scala/tasty/reflect/ImportSelectorOps.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package reflect
33

44
trait ImportSelectorOps extends Core {
55

6-
given SimpleSelectorOps: (self: SimpleSelector) {
6+
given simpleSelectorOps: extension (self: SimpleSelector) {
77
def selection(given ctx: Context): Id =
88
internal.SimpleSelector_selection(self)
99
}
@@ -13,7 +13,7 @@ trait ImportSelectorOps extends Core {
1313
object SimpleSelector
1414
def unapply(x: SimpleSelector)(given ctx: Context): Option[Id] = Some(x.selection)
1515

16-
given RenameSelectorOps: (self: RenameSelector) {
16+
given renameSelectorOps: extension (self: RenameSelector) {
1717
def from(given ctx: Context): Id =
1818
internal.RenameSelector_from(self)
1919

@@ -26,7 +26,7 @@ trait ImportSelectorOps extends Core {
2626
object RenameSelector
2727
def unapply(x: RenameSelector)(given ctx: Context): Option[(Id, Id)] = Some((x.from, x.to))
2828

29-
given OmitSelectorOps: (self: OmitSelector) {
29+
given omitSelectorOps: extension (self: OmitSelector) {
3030
def omitted(given ctx: Context): Id =
3131
internal.SimpleSelector_omitted(self)
3232
}

library/src/scala/tasty/reflect/PositionOps.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package scala.tasty.reflect
22

33
trait PositionOps extends Core {
44

5-
given PositionOps: (pos: Position) {
5+
given positionOps: extension (pos: Position) {
66

77
/** The start offset in the source file */
88
def start: Int = internal.Position_start(pos)
@@ -33,7 +33,7 @@ trait PositionOps extends Core {
3333

3434
}
3535

36-
given SourceFileOps: (sourceFile: SourceFile) {
36+
given sourceFileOps: extension (sourceFile: SourceFile) {
3737

3838
/** Path to this source file */
3939
def jpath: java.nio.file.Path = internal.SourceFile_jpath(sourceFile)

library/src/scala/tasty/reflect/SignatureOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ trait SignatureOps extends Core {
99
Some((sig.paramSigs, sig.resultSig))
1010
}
1111

12-
given SignatureOps: (sig: Signature) {
12+
given signatureOps: extension (sig: Signature) {
1313

1414
/** The signatures of the method parameters.
1515
*

library/src/scala/tasty/reflect/SymbolOps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ trait SymbolOps extends Core { selfSymbolOps: FlagsOps =>
1414
internal.Symbol_noSymbol
1515
}
1616

17-
given SymbolOps: (self: Symbol) {
17+
given symbolOps: extension (self: Symbol) {
1818

1919
/** Owner of this symbol. The owner is the symbol in which this symbol is defined */
2020
def owner(given ctx: Context): Symbol = internal.Symbol_owner(self)

0 commit comments

Comments
 (0)