Skip to content

Commit fe45e5a

Browse files
committed
Drop old extension method syntax
1 parent bb23fea commit fe45e5a

File tree

7 files changed

+10
-95
lines changed

7 files changed

+10
-95
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -837,36 +837,10 @@ object desugar {
837837
*
838838
* <module> val name: name$ = New(name$)
839839
* <module> final class name$ extends parents { self: name.type => body }
840-
*
841-
* Special case for extension methods with collective parameters. Expand:
842-
*
843-
* given object name[tparams](x: T) extends parents { self => bpdy }
844-
*
845-
* to:
846-
*
847-
* given object name extends parents { self => body' }
848-
*
849-
* where every definition in `body` is expanded to an extension method
850-
* taking type parameters `tparams` and a leading paramter `(x: T)`.
851-
* See: collectiveExtensionBody
852-
* TODO: drop this part
853840
*/
854841
def moduleDef(mdef: ModuleDef)(using Context): Tree = {
855842
val impl = mdef.impl
856843
val mods = mdef.mods
857-
impl.constr match {
858-
case DefDef(_, tparams, vparamss @ (vparam :: Nil) :: givenParamss, _, _) =>
859-
// Transform collective extension
860-
assert(mods.is(Given))
861-
return moduleDef(
862-
cpy.ModuleDef(mdef)(
863-
mdef.name,
864-
cpy.Template(impl)(
865-
constr = emptyConstructor,
866-
body = collectiveExtensionBody(impl.body, tparams, vparamss))))
867-
case _ =>
868-
}
869-
870844
val moduleName = normalizeName(mdef, impl).asTermName
871845
def isEnumCase = mods.isEnumCase
872846

compiler/src/dotty/tools/dotc/ast/Positioned.scala

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,6 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Pro
147147
}
148148
}
149149

150-
/** A hook that can be overridden if overlap checking in `checkPos` should be
151-
* disabled for this node.
152-
*/
153-
def disableOverlapChecks = false
154-
155150
/** Check that all positioned items in this tree satisfy the following conditions:
156151
* - Parent spans contain child spans
157152
* - If item is a non-empty tree, it has a position

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -761,11 +761,6 @@ object Trees {
761761
assert(tpt != genericEmptyTree)
762762
def unforced: LazyTree[T] = preRhs
763763
protected def force(x: Tree[T @uncheckedVariance]): Unit = preRhs = x
764-
765-
override def disableOverlapChecks = rawMods.is(Extension)
766-
// disable order checks for extension methods as long as we parse
767-
// type parameters both before and after the leading parameter section.
768-
// TODO drop this once syntax of type parameters has settled.
769764
}
770765

771766
/** mods class name template or

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ object Flags {
495495

496496
/** Flags that can apply to a module val */
497497
val RetainedModuleValFlags: FlagSet = RetainedModuleValAndClassFlags |
498-
Override | Final | Method | Implicit | Given | Lazy | Extension |
498+
Override | Final | Method | Implicit | Given | Lazy |
499499
Accessor | AbsOverride | StableRealizable | Captured | Synchronized | Erased
500500

501501
/** Flags that can apply to a module class */

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

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ object Parsers {
225225
|| defIntroTokens.contains(in.token)
226226
|| allowedMods.contains(in.token)
227227
|| in.isSoftModifierInModifierPosition && !excludedSoftModifiers.contains(in.name)
228-
|| isIdent(nme.extension) && followingIsOldExtension()
229228

230229
def isStatSep: Boolean = in.isNewLine || in.token == SEMI
231230

@@ -919,23 +918,10 @@ object Parsers {
919918
skipParams()
920919
lookahead.isIdent(nme.as)
921920

922-
def followingIsNewExtension() =
921+
def followingIsExtension() =
923922
val next = in.lookahead.token
924923
next == LBRACKET || next == LPAREN
925924

926-
def followingIsOldExtension() =
927-
val lookahead = in.LookaheadScanner()
928-
lookahead.nextToken()
929-
if lookahead.isIdent && !lookahead.isIdent(nme.on) then
930-
lookahead.nextToken()
931-
if lookahead.isNewLine then
932-
lookahead.nextToken()
933-
lookahead.isIdent(nme.on)
934-
|| lookahead.token == LBRACE
935-
|| lookahead.token == COLON
936-
937-
def followingIsExtension() = followingIsOldExtension() || followingIsNewExtension()
938-
939925
/* --------- OPERAND/OPERATOR STACK --------------------------------------- */
940926

941927
var opStack: List[OpInfo] = Nil
@@ -1311,7 +1297,7 @@ object Parsers {
13111297
case stat: MemberDef if !stat.name.isEmpty =>
13121298
if stat.name == nme.CONSTRUCTOR then in.token == THIS
13131299
else in.isIdent && in.name == stat.name.toTermName
1314-
case ModuleDef(_, Template(_, Nil, _, _)) | ExtMethods(_, _, _) =>
1300+
case ExtMethods(_, _, _) =>
13151301
in.token == IDENTIFIER && in.name == nme.extension
13161302
case PackageDef(pid: RefTree, _) =>
13171303
in.isIdent && in.name == pid.name
@@ -3465,11 +3451,8 @@ object Parsers {
34653451
case GIVEN =>
34663452
givenDef(start, mods, atSpan(in.skipToken()) { Mod.Given() })
34673453
case _ =>
3468-
if isIdent(nme.extension) && followingIsOldExtension() then
3469-
extensionDef(start, mods)
3470-
else
3471-
syntaxErrorOrIncomplete(ExpectedStartOfTopLevelDefinition())
3472-
EmptyTree
3454+
syntaxErrorOrIncomplete(ExpectedStartOfTopLevelDefinition())
3455+
EmptyTree
34733456
}
34743457

34753458
/** ClassDef ::= id ClassConstr TemplateOpt
@@ -3614,28 +3597,6 @@ object Parsers {
36143597
finalizeDef(gdef, mods1, start)
36153598
}
36163599

3617-
/** ExtensionDef ::= [id] [‘on’ ExtParamClause {UsingParamClause}] TemplateBody
3618-
*/
3619-
def extensionDef(start: Offset, mods: Modifiers): ModuleDef =
3620-
in.nextToken()
3621-
val nameOffset = in.offset
3622-
val name = if isIdent && !isIdent(nme.on) then ident() else EmptyTermName
3623-
val (tparams, vparamss, extensionFlag) =
3624-
if isIdent(nme.on) then
3625-
in.nextToken()
3626-
val tparams = typeParamClauseOpt(ParamOwner.Def)
3627-
val extParams = paramClause(0, prefix = true)
3628-
val givenParamss = paramClauses(givenOnly = true)
3629-
(tparams, extParams :: givenParamss, Extension)
3630-
else
3631-
(Nil, Nil, EmptyFlags)
3632-
possibleTemplateStart()
3633-
if !in.isNestedStart then syntaxError("Extension without extension methods")
3634-
val templ = templateBodyOpt(makeConstructor(tparams, vparamss), Nil, Nil)
3635-
templ.body.foreach(checkExtensionMethod(tparams, vparamss, _))
3636-
val edef = atSpan(start, nameOffset, in.offset)(ModuleDef(name, templ))
3637-
finalizeDef(edef, addFlag(mods, Given | extensionFlag), start)
3638-
36393600
/** Extension ::= ‘extension’ [DefTypeParamClause] ‘(’ DefParam ‘)’
36403601
* {UsingParamClause} ExtMethods
36413602
*/
@@ -3816,7 +3777,7 @@ object Parsers {
38163777
stats ++= importClause(IMPORT, mkImport(outermost))
38173778
else if (in.token == EXPORT)
38183779
stats ++= importClause(EXPORT, Export.apply)
3819-
else if isIdent(nme.extension) && followingIsNewExtension() then
3780+
else if isIdent(nme.extension) && followingIsExtension() then
38203781
stats += extension()
38213782
else if isDefIntro(modifierTokens)
38223783
stats +++= defOrDcl(in.offset, defAnnotsMods(modifierTokens))
@@ -3870,7 +3831,7 @@ object Parsers {
38703831
stats ++= importClause(IMPORT, mkImport())
38713832
else if (in.token == EXPORT)
38723833
stats ++= importClause(EXPORT, Export.apply)
3873-
else if isIdent(nme.extension) && followingIsNewExtension() then
3834+
else if isIdent(nme.extension) && followingIsExtension() then
38743835
stats += extension()
38753836
else if (isDefIntro(modifierTokensOrCase))
38763837
stats +++= defOrDcl(in.offset, defAnnotsMods(modifierTokens))
@@ -3952,7 +3913,7 @@ object Parsers {
39523913
stats += expr(Location.InBlock)
39533914
else if in.token == IMPLICIT && !in.inModifierPosition() then
39543915
stats += closure(in.offset, Location.InBlock, modifiers(BitSet(IMPLICIT)))
3955-
else if isIdent(nme.extension) && followingIsNewExtension() then
3916+
else if isIdent(nme.extension) && followingIsExtension() then
39563917
stats += extension()
39573918
else if isDefIntro(localModifierTokens, excludedSoftModifiers = Set(nme.`opaque`)) then
39583919
stats +++= localDef(in.offset)

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
745745
protected def nameIdText[T >: Untyped](tree: NameTree[T], dropExtension: Boolean = false): Text =
746746
if (tree.hasType && tree.symbol.exists) {
747747
var str = nameString(tree.symbol)
748-
if tree.symbol.isExtensionMethod && dropExtension && str.startsWith("extension_") then
748+
if tree.symbol.isAllOf(ExtensionMethod) && dropExtension && str.startsWith("extension_") then
749749
str = str.drop("extension_".length)
750750
tree match {
751751
case tree: RefTree => withPos(str, tree.sourcePos)
@@ -788,7 +788,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
788788
import untpd._
789789
dclTextOr(tree) {
790790
val defKeyword = modText(tree.mods, tree.symbol, keywordStr("def"), isType = false)
791-
val isExtension = tree.hasType && tree.symbol.isExtensionMethod
791+
val isExtension = tree.hasType && tree.symbol.isAllOf(ExtensionMethod)
792792
withEnclosingDef(tree) {
793793
val (prefix, vparamss) =
794794
if isExtension then

compiler/src/dotty/tools/dotc/transform/SymUtils.scala

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,6 @@ object SymUtils {
213213
def isTypeSplice(using Context): Boolean =
214214
self == defn.QuotedType_splice
215215

216-
/** Is symbol an extension method? Accessors are excluded since
217-
* after the getters phase collective extension objects become accessors
218-
*/
219-
def isExtensionMethod(using Context): Boolean =
220-
self.isAllOf(ExtensionMethod, butNot = Accessor)
221-
222-
/** Is symbol the module class of a collective extension object? */
223-
def isCollectiveExtensionClass(using Context): Boolean =
224-
self.is(ModuleClass) && self.sourceModule.is(Extension) && !self.sourceModule.isExtensionMethod
225-
226216
def isScalaStatic(using Context): Boolean =
227217
self.hasAnnotation(defn.ScalaStaticAnnot)
228218

0 commit comments

Comments
 (0)