Skip to content

Commit f61b4e9

Browse files
committed
Rename Extension -> ExtensionMethod
1 parent 1b60065 commit f61b4e9

File tree

11 files changed

+24
-62
lines changed

11 files changed

+24
-62
lines changed

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

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -895,46 +895,10 @@ object desugar {
895895
vparams1 :: ext.vparamss ::: vparamss1
896896
case _ =>
897897
ext.vparamss ++ mdef.vparamss
898-
).withMods(mdef.mods | Extension)
898+
).withMods(mdef.mods | ExtensionMethod)
899899
)
900900
}
901901

902-
/** Transform the statements of a collective extension
903-
* @param stats the original statements as they were parsed
904-
* @param tparams the collective type parameters
905-
* @param vparamss the collective value parameters, consisting
906-
* of a single leading value parameter, followed by
907-
* zero or more context parameter clauses
908-
*
909-
* Note: It is already assured by Parser.checkExtensionMethod that all
910-
* statements conform to requirements.
911-
*
912-
* Each method in stats is transformed into an extension method. Example:
913-
*
914-
* extension on [Ts](x: T)(using C):
915-
* def f(y: T) = ???
916-
* def g(z: T) = f(z)
917-
*
918-
* is turned into
919-
*
920-
* extension:
921-
* <extension> def f[Ts](x: T)(using C)(y: T) = ???
922-
* <extension> def g[Ts](x: T)(using C)(z: T) = f(z)
923-
*/
924-
def collectiveExtensionBody(stats: List[Tree],
925-
tparams: List[TypeDef], vparamss: List[List[ValDef]])(using Context): List[Tree] =
926-
for stat <- stats yield
927-
stat match
928-
case mdef: DefDef =>
929-
cpy.DefDef(mdef)(
930-
name = mdef.name.toExtensionName,
931-
tparams = tparams ++ mdef.tparams,
932-
vparamss = vparamss ::: mdef.vparamss,
933-
).withMods(mdef.mods | Extension)
934-
case mdef =>
935-
mdef
936-
end collectiveExtensionBody
937-
938902
/** Transforms
939903
*
940904
* <mods> type $T >: Low <: Hi
@@ -971,7 +935,7 @@ object desugar {
971935
report.error(IllegalRedefinitionOfStandardKind(kind, name), errPos)
972936
name = name.errorName
973937
}
974-
if name.isExtensionName && !mdef.mods.is(Extension) then
938+
if name.isExtensionName && !mdef.mods.is(ExtensionMethod) then
975939
report.error(em"illegal method name: $name may not start with `extension_`", errPos)
976940
name
977941
}
@@ -982,7 +946,7 @@ object desugar {
982946
case impl: Template =>
983947
if impl.parents.isEmpty then
984948
impl.body.find {
985-
case dd: DefDef if dd.mods.is(Extension) => true
949+
case dd: DefDef if dd.mods.is(ExtensionMethod) => true
986950
case _ => false
987951
}
988952
match

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import util.Spans._
66
import util.{SourceFile, NoSource, SourcePosition, SrcPos}
77
import core.Contexts._
88
import core.Decorators._
9-
import core.Flags.{JavaDefined, Extension}
9+
import core.Flags.{JavaDefined, ExtensionMethod}
1010
import core.StdNames.nme
1111
import ast.Trees.mods
1212
import annotation.constructorOnly
@@ -174,7 +174,7 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Src
174174
s"position error: position not set for $tree # ${tree.uniqueId}")
175175
case _ =>
176176
}
177-
if (nonOverlapping && !disableOverlapChecks) {
177+
if nonOverlapping then
178178
this match {
179179
case _: XMLBlock =>
180180
// FIXME: Trees generated by the XML parser do not satisfy `checkPos`
@@ -192,7 +192,6 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Src
192192
}
193193
lastPositioned = p
194194
lastSpan = p.span
195-
}
196195
p.checkPos(nonOverlapping)
197196
case m: untpd.Modifiers =>
198197
m.annotations.foreach(check)
@@ -207,7 +206,7 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Src
207206
// Leave out tparams, they are copied with wrong positions from parent class
208207
check(tree.mods)
209208
check(tree.vparamss)
210-
case tree: DefDef if tree.mods.is(Extension) =>
209+
case tree: DefDef if tree.mods.is(ExtensionMethod) =>
211210
tree.vparamss match {
212211
case vparams1 :: vparams2 :: rest if !isLeftAssoc(tree.name) =>
213212
check(tree.tparams)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ object Flags {
302302
val (_, HasDefault @ _, _) = newFlags(27, "<hasdefault>")
303303

304304
/** An extension method, or a collective extension instance */
305-
val (_, Extension @ _, _) = newFlags(28, "<extension>")
305+
val (Extension @ _, ExtensionMethod @ _, _) = newFlags(28, "<extension>")
306306

307307
/** An inferable (`given`) parameter */
308308
val (Given @ _, _, _) = newFlags(29, "given")
@@ -527,7 +527,6 @@ object Flags {
527527
val DeferredOrTypeParam: FlagSet = Deferred | TypeParam // type symbols without right-hand sides
528528
val EnumValue: FlagSet = Enum | StableRealizable // A Scala enum value
529529
val StableOrErased: FlagSet = Erased | StableRealizable // Assumed to be pure
530-
val ExtensionMethod: FlagSet = Extension | Method
531530
val FinalOrInline: FlagSet = Final | Inline
532531
val FinalOrModuleClass: FlagSet = Final | ModuleClass // A module class or a final class
533532
val EffectivelyFinalFlags: FlagSet = Final | Private

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ object SymDenotations {
11041104
* provided the extension method appears in the same class.
11051105
*/
11061106
final def enclosingExtensionMethod(using Context): Symbol =
1107-
if this.isAllOf(ExtensionMethod) then symbol
1107+
if this.is(ExtensionMethod) then symbol
11081108
else if this.isClass then NoSymbol
11091109
else if this.exists then owner.enclosingExtensionMethod
11101110
else NoSymbol

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3291,7 +3291,7 @@ object Parsers {
32913291
def extParamss() =
32923292
try paramClause(0, prefix = true) :: Nil
32933293
finally
3294-
mods1 = addFlag(mods, Extension)
3294+
mods1 = addFlag(mods, ExtensionMethod)
32953295
if in.token == DOT then in.nextToken()
32963296
else
32973297
isInfix = true
@@ -3305,14 +3305,14 @@ object Parsers {
33053305
(Nil, Nil)
33063306
val ident = termIdent()
33073307
var name = ident.name.asTermName
3308-
if mods1.is(Extension) then name = name.toExtensionName
3308+
if mods1.is(ExtensionMethod) then name = name.toExtensionName
33093309
if isInfix && !name.isOperatorName then
33103310
val infixAnnot = Apply(wrapNew(scalaAnnotationDot(tpnme.infix)), Nil)
33113311
.withSpan(Span(start, start))
33123312
mods1 = mods1.withAddedAnnotation(infixAnnot)
33133313
val tparams =
33143314
if in.token == LBRACKET then
3315-
if mods1.is(Extension) then syntaxError("no type parameters allowed here")
3315+
if mods1.is(ExtensionMethod) then syntaxError("no type parameters allowed here")
33163316
typeParamClause(ParamOwner.Def)
33173317
else leadingTparams
33183318
val vparamss = paramClauses() match
@@ -3546,9 +3546,9 @@ object Parsers {
35463546
def checkExtensionMethod(tparams: List[Tree],
35473547
vparamss: List[List[Tree]], stat: Tree): Unit = stat match {
35483548
case stat: DefDef =>
3549-
if stat.mods.is(Extension) && vparamss.nonEmpty then
3549+
if stat.mods.is(ExtensionMethod) && vparamss.nonEmpty then
35503550
syntaxError(i"no extension method allowed here since leading parameter was already given", stat.span)
3551-
else if !stat.mods.is(Extension) && vparamss.isEmpty then
3551+
else if !stat.mods.is(ExtensionMethod) && vparamss.isEmpty then
35523552
syntaxError(i"an extension method is required here", stat.span)
35533553
else if tparams.nonEmpty && stat.tparams.nonEmpty then
35543554
syntaxError(i"extension method cannot have type parameters since some were already given previously",

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.isAllOf(ExtensionMethod) && dropExtension && str.startsWith("extension_") then
748+
if tree.symbol.is(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.isAllOf(ExtensionMethod)
791+
val isExtension = tree.hasType && tree.symbol.is(ExtensionMethod)
792792
withEnclosingDef(tree) {
793793
val (prefix, vparamss) =
794794
if isExtension then

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2108,8 +2108,8 @@ trait Applications extends Compatibility {
21082108
}
21092109
def isExtension(tree: Tree): Boolean = methPart(tree) match {
21102110
case Inlined(call, _, _) => isExtension(call)
2111-
case tree @ Select(qual, nme.apply) => tree.symbol.is(Extension) || isExtension(qual)
2112-
case tree => tree.symbol.is(Extension)
2111+
case tree @ Select(qual, nme.apply) => tree.symbol.is(ExtensionMethod) || isExtension(qual)
2112+
case tree => tree.symbol.is(ExtensionMethod)
21132113
}
21142114
if (!isExtension(app))
21152115
report.error(em"not an extension method: $methodRef", receiver.srcPos)

compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ trait ImportSuggestions:
220220
.alternatives
221221
.map(mbr => TermRef(site, mbr.symbol))
222222
.filter(ref =>
223-
ref.symbol.isAllOf(ExtensionMethod)
223+
ref.symbol.is(ExtensionMethod)
224224
&& isApplicableMethodRef(ref, argType :: Nil, WildcardType))
225225
.headOption
226226

@@ -317,7 +317,7 @@ trait ImportSuggestions:
317317
else (headMatches, "make progress towards fixing")
318318
def importString(ref: TermRef): String =
319319
val imported =
320-
if ref.symbol.isAllOf(ExtensionMethod) then
320+
if ref.symbol.is(ExtensionMethod) then
321321
s"${ctx.printer.toTextPrefix(ref.prefix).show}${ref.symbol.name.dropExtension}"
322322
else
323323
ctx.printer.toTextRef(ref).show

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ class Namer { typer: Typer =>
992992
else
993993
(EmptyFlags, mbr.info.ensureMethodic)
994994
var mbrFlags = Exported | Method | Final | maybeStable | sym.flags & RetainedExportFlags
995-
if sym.isAllOf(ExtensionMethod) then mbrFlags |= Extension
995+
if sym.is(ExtensionMethod) then mbrFlags |= ExtensionMethod
996996
val forwarderName = checkNoConflict(alias, isPrivate = false, span)
997997
newSymbol(cls, forwarderName, mbrFlags, mbrInfo, coord = span)
998998
}

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,9 @@ object RefChecks {
354354
overrideError("cannot be used here - classes can only override abstract types")
355355
else if (other.isEffectivelyFinal) // (1.2)
356356
overrideError(i"cannot override final member ${other.showLocated}")
357-
else if (member.isAllOf(ExtensionMethod) && !other.isAllOf(ExtensionMethod)) // (1.3)
357+
else if (member.is(ExtensionMethod) && !other.is(ExtensionMethod)) // (1.3)
358358
overrideError("is an extension method, cannot override a normal method")
359-
else if (other.isAllOf(ExtensionMethod) && !member.isAllOf(ExtensionMethod)) // (1.3)
359+
else if (other.is(ExtensionMethod) && !member.is(ExtensionMethod)) // (1.3)
360360
overrideError("is a normal method, cannot override an extension method")
361361
else if (!other.is(Deferred) &&
362362
!other.name.is(DefaultGetterName) &&

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ class Typer extends Namer
215215
val termName = name.toTermName
216216

217217
def adjustExtension(name: Name) =
218-
if required.is(Extension) then name.toExtensionName else name
218+
if required.is(ExtensionMethod) then name.toExtensionName else name
219219

220220
def recur(selectors: List[untpd.ImportSelector]): Type = selectors match
221221
case selector :: rest =>
@@ -829,7 +829,7 @@ class Typer extends Namer
829829
ctx.owner.name.is(TraitSetterName) || ctx.owner.isStaticConstructor
830830

831831
lhsCore match
832-
case Apply(fn, _) if fn.symbol.isExtensionMethod =>
832+
case Apply(fn, _) if fn.symbol.is(ExtensionMethod) =>
833833
def toSetter(fn: Tree): untpd.Tree = fn match
834834
case fn @ Ident(name: TermName) =>
835835
untpd.cpy.Ident(fn)(name.setterName)

0 commit comments

Comments
 (0)