Skip to content

Commit c09293e

Browse files
committed
Use new extension syntax in compiler
1 parent 480f95f commit c09293e

File tree

17 files changed

+66
-58
lines changed

17 files changed

+66
-58
lines changed

compiler/src/dotty/tools/backend/jvm/BTypesFromSymbols.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I) extends BTypes {
121121
* All interfaces implemented by a class, except for those inherited through the superclass.
122122
* Redundant interfaces are removed unless there is a super call to them.
123123
*/
124-
def (sym: Symbol).superInterfaces: List[Symbol] = {
124+
extension (sym: Symbol) def superInterfaces: List[Symbol] = {
125125
val directlyInheritedTraits = sym.directlyInheritedTraits
126126
val directlyInheritedTraitsSet = directlyInheritedTraits.toSet
127127
val allBaseClasses = directlyInheritedTraits.iterator.flatMap(_.asClass.baseClasses.drop(1)).toSet
@@ -272,8 +272,9 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I) extends BTypes {
272272
* object T { def f { object U } }
273273
* the owner of U is T, so UModuleClass.isStatic is true. Phase travel does not help here.
274274
*/
275-
private def (sym: Symbol).isOriginallyStaticOwner: Boolean =
276-
sym.is(PackageClass) || sym.is(ModuleClass) && sym.originalOwner.originalLexicallyEnclosingClass.isOriginallyStaticOwner
275+
extension (sym: Symbol):
276+
private def isOriginallyStaticOwner: Boolean =
277+
sym.is(PackageClass) || sym.is(ModuleClass) && sym.originalOwner.originalLexicallyEnclosingClass.isOriginallyStaticOwner
277278

278279
/**
279280
* Return the Java modifiers for the given symbol.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ object Trees {
333333
def namedType: NamedType = tpe.asInstanceOf[NamedType]
334334
}
335335

336-
def (mdef: untpd.DefTree).mods: untpd.Modifiers = mdef.rawMods
336+
extension (mdef: untpd.DefTree) def mods: untpd.Modifiers = mdef.rawMods
337337

338338
abstract class NamedDefTree[-T >: Untyped](implicit @constructorOnly src: SourceFile) extends NameTree[T] with DefTree[T] {
339339
type ThisTree[-T >: Untyped] <: NamedDefTree[T]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
775775
}
776776

777777
/** Is there a subtree of this tree that satisfies predicate `p`? */
778-
def (tree: Tree) existsSubTree(p: Tree => Boolean)(implicit ctx: Context): Boolean = {
778+
extension (tree: Tree) def existsSubTree(p: Tree => Boolean)(implicit ctx: Context): Boolean = {
779779
val acc = new UntypedTreeAccumulator[Boolean] {
780780
def apply(x: Boolean, t: Tree)(implicit ctx: Context) = x || p(t) || foldOver(x, t)
781781
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ object Decorators {
2121
* a simple collective extension.
2222
*/
2323
implicit object PreNamedString:
24-
def (pn: PreName).toTypeName: TypeName = pn match
24+
extension (pn: PreName) def toTypeName: TypeName = pn match
2525
case s: String => typeName(s)
2626
case n: Name => n.toTypeName
27-
def (pn: PreName).toTermName: TermName = pn match
27+
extension (pn: PreName) def toTermName: TermName = pn match
2828
case s: String => termName(s)
2929
case n: Name => n.toTermName
3030

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

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

2323
type Flag = opaques.Flag
2424

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

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
727727
}
728728

729729
/** Print modifiers from symbols if tree has type, overriding the behavior in Trees. */
730-
def (mdef: untpd.DefTree).mods: untpd.Modifiers =
730+
extension (mdef: untpd.DefTree) def mods: untpd.Modifiers =
731731
if mdef.hasType then Modifiers(mdef.symbol) else mdef.rawMods
732732

733733
private def Modifiers(sym: Symbol): Modifiers = untpd.Modifiers(

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

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,10 @@ class ExtractSemanticDB extends Phase:
260260

261261
case _ => None
262262

263-
private inline def (tpe: Types.Type) isAnnotatedByUnchecked(using Context) = tpe match
264-
case Types.AnnotatedType(_, annot) => annot.symbol == defn.UncheckedAnnot
265-
case _ => false
263+
extension (tpe: Types.Type):
264+
private inline def isAnnotatedByUnchecked(using Context) = tpe match
265+
case Types.AnnotatedType(_, annot) => annot.symbol == defn.UncheckedAnnot
266+
case _ => false
266267

267268
def collectPats(pat: Tree): List[Tree] =
268269

@@ -282,11 +283,12 @@ class ExtractSemanticDB extends Phase:
282283

283284
end PatternValDef
284285

285-
private def (tree: NamedDefTree) adjustedNameSpan(using Context): Span =
286-
if tree.span.exists && tree.name.isAnonymousFunctionName || tree.name.isAnonymousClassName
287-
Span(tree.span.point)
288-
else
289-
tree.nameSpan
286+
extension (tree: NamedDefTree):
287+
private def adjustedNameSpan(using Context): Span =
288+
if tree.span.exists && tree.name.isAnonymousFunctionName || tree.name.isAnonymousClassName
289+
Span(tree.span.point)
290+
else
291+
tree.nameSpan
290292

291293
/** Add semanticdb name of the given symbol to string builder */
292294
private def addSymName(b: StringBuilder, sym: Symbol)(using Context): Unit =
@@ -496,12 +498,14 @@ class ExtractSemanticDB extends Phase:
496498
val start = if idx >= 0 then idx else span.start
497499
Span(start, start + sym.name.show.length, start)
498500

499-
private inline def (list: List[List[ValDef]]) isSingleArg = list match
500-
case (_::Nil)::Nil => true
501-
case _ => false
501+
extension (list: List[List[ValDef]]):
502+
private inline def isSingleArg = list match
503+
case (_::Nil)::Nil => true
504+
case _ => false
502505

503-
private def (tree: DefDef) isSetterDef(using Context): Boolean =
504-
tree.name.isSetterName && tree.mods.is(Accessor) && tree.vparamss.isSingleArg
506+
extension (tree: DefDef):
507+
private def isSetterDef(using Context): Boolean =
508+
tree.name.isSetterName && tree.mods.is(Accessor) && tree.vparamss.isSingleArg
505509

506510
private def findGetters(ctorParams: Set[Names.TermName], body: List[Tree])(using Context): Map[Names.TermName, ValDef] =
507511
if ctorParams.isEmpty || body.isEmpty then
@@ -525,26 +529,27 @@ class ExtractSemanticDB extends Phase:
525529
else limit
526530
Span(start max limit, end)
527531

528-
private extension on (span: Span):
529-
def hasLength: Boolean = span.start != span.end
530-
def zeroLength: Boolean = span.start == span.end
532+
extension (span: Span):
533+
private def hasLength: Boolean = span.start != span.end
534+
private def zeroLength: Boolean = span.start == span.end
531535

532536
/**Consume head while not an import statement.
533537
* Returns the rest of the list after the first import, or else the empty list
534538
*/
535-
@tailrec
536-
private def (body: List[Tree]) foreachUntilImport(op: Tree => Unit): List[Tree] = body match
537-
case ((_: Import) :: rest) => rest
538-
case stat :: rest =>
539-
op(stat)
540-
rest.foreachUntilImport(op)
541-
case Nil => Nil
542-
543-
private def (sym: Symbol) adjustIfCtorTyparam(using Context) =
544-
if sym.isType && sym.owner.exists && sym.owner.isConstructor
545-
matchingMemberType(sym, sym.owner.owner)
546-
else
547-
sym
539+
extension (body: List[Tree]):
540+
@tailrec private def foreachUntilImport(op: Tree => Unit): List[Tree] = body match
541+
case ((_: Import) :: rest) => rest
542+
case stat :: rest =>
543+
op(stat)
544+
rest.foreachUntilImport(op)
545+
case Nil => Nil
546+
547+
extension (sym: Symbol):
548+
private def adjustIfCtorTyparam(using Context) =
549+
if sym.isType && sym.owner.exists && sym.owner.isConstructor
550+
matchingMemberType(sym, sym.owner.owner)
551+
else
552+
sym
548553

549554
private inline def matchingMemberType(ctorTypeParam: Symbol, classSym: Symbol)(using Context) =
550555
classSym.info.member(ctorTypeParam.name).symbol

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ object Scala3:
105105

106106
val setterName = sym.name.toTermName.setterName
107107

108-
inline def (t: Type) matchingType = t.paramInfoss match
108+
extension (t: Type) inline def matchingType = t.paramInfoss match
109109
case (arg::Nil)::Nil => t.resultType == defn.UnitType && arg == sym.info
110110
case _ => false
111111

@@ -139,9 +139,10 @@ object Scala3:
139139

140140
end LocalSymbol
141141

142-
private inline def (char: Char) isGlobalTerminal = (char: @switch) match
143-
case '/' | '.' | '#' | ']' | ')' => true
144-
case _ => false
142+
extension (char: Char):
143+
private inline def isGlobalTerminal = (char: @switch) match
144+
case '/' | '.' | '#' | ']' | ')' => true
145+
case _ => false
145146

146147
extension StringOps on (symbol: String):
147148

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,5 @@ object Tools:
137137
sb.append(if occ.role.isReference then " -> " else " <- ").append(occ.symbol).nl
138138
end processOccurrence
139139

140-
private inline def (sb: StringBuilder) nl = sb.append(System.lineSeparator)
140+
extension (sb: StringBuilder):
141+
private inline def nl = sb.append(System.lineSeparator)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ object ExplicitOuter {
323323
tpe
324324
}
325325

326-
def (sym: Symbol).isOuterParamAccessor(using Context): Boolean =
326+
extension (sym: Symbol) def isOuterParamAccessor(using Context): Boolean =
327327
sym.is(ParamAccessor) && sym.name == nme.OUTER
328328

329329
def outer(implicit ctx: Context): OuterOps = new OuterOps(ctx)

0 commit comments

Comments
 (0)