diff --git a/compiler/src/dotty/tools/backend/jvm/BTypesFromSymbols.scala b/compiler/src/dotty/tools/backend/jvm/BTypesFromSymbols.scala index 000a9e851da1..3e6fbe96b13b 100644 --- a/compiler/src/dotty/tools/backend/jvm/BTypesFromSymbols.scala +++ b/compiler/src/dotty/tools/backend/jvm/BTypesFromSymbols.scala @@ -123,7 +123,7 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I) extends BTypes { * All interfaces implemented by a class, except for those inherited through the superclass. * Redundant interfaces are removed unless there is a super call to them. */ - def (sym: Symbol).superInterfaces: List[Symbol] = { + extension (sym: Symbol) def superInterfaces: List[Symbol] = { val directlyInheritedTraits = sym.directlyInheritedTraits val directlyInheritedTraitsSet = directlyInheritedTraits.toSet val allBaseClasses = directlyInheritedTraits.iterator.flatMap(_.asClass.baseClasses.drop(1)).toSet @@ -275,8 +275,9 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I) extends BTypes { * object T { def f { object U } } * the owner of U is T, so UModuleClass.isStatic is true. Phase travel does not help here. */ - private def (sym: Symbol).isOriginallyStaticOwner: Boolean = - sym.is(PackageClass) || sym.is(ModuleClass) && sym.originalOwner.originalLexicallyEnclosingClass.isOriginallyStaticOwner + extension (sym: Symbol): + private def isOriginallyStaticOwner: Boolean = + sym.is(PackageClass) || sym.is(ModuleClass) && sym.originalOwner.originalLexicallyEnclosingClass.isOriginallyStaticOwner /** * Return the Java modifiers for the given symbol. diff --git a/compiler/src/dotty/tools/dotc/ast/Trees.scala b/compiler/src/dotty/tools/dotc/ast/Trees.scala index 65646decbd77..3dae20f5ce93 100644 --- a/compiler/src/dotty/tools/dotc/ast/Trees.scala +++ b/compiler/src/dotty/tools/dotc/ast/Trees.scala @@ -333,7 +333,7 @@ object Trees { def namedType: NamedType = tpe.asInstanceOf[NamedType] } - def (mdef: untpd.DefTree).mods: untpd.Modifiers = mdef.rawMods + extension (mdef: untpd.DefTree) def mods: untpd.Modifiers = mdef.rawMods abstract class NamedDefTree[-T >: Untyped](implicit @constructorOnly src: SourceFile) extends NameTree[T] with DefTree[T] { type ThisTree[-T >: Untyped] <: NamedDefTree[T] diff --git a/compiler/src/dotty/tools/dotc/ast/untpd.scala b/compiler/src/dotty/tools/dotc/ast/untpd.scala index cbf8277378f5..ee0ceff4f537 100644 --- a/compiler/src/dotty/tools/dotc/ast/untpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/untpd.scala @@ -775,7 +775,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo { } /** Is there a subtree of this tree that satisfies predicate `p`? */ - def (tree: Tree) existsSubTree(p: Tree => Boolean)(using Context): Boolean = { + extension (tree: Tree) def existsSubTree(p: Tree => Boolean)(using Context): Boolean = { val acc = new UntypedTreeAccumulator[Boolean] { def apply(x: Boolean, t: Tree)(using Context) = x || p(t) || foldOver(x, t) } diff --git a/compiler/src/dotty/tools/dotc/core/Decorators.scala b/compiler/src/dotty/tools/dotc/core/Decorators.scala index 670d99ea10c1..e1ad1130c1db 100644 --- a/compiler/src/dotty/tools/dotc/core/Decorators.scala +++ b/compiler/src/dotty/tools/dotc/core/Decorators.scala @@ -21,10 +21,10 @@ object Decorators { * a simple collective extension. */ implicit object PreNamedString: - def (pn: PreName).toTypeName: TypeName = pn match + extension (pn: PreName) def toTypeName: TypeName = pn match case s: String => typeName(s) case n: Name => n.toTypeName - def (pn: PreName).toTermName: TermName = pn match + extension (pn: PreName) def toTermName: TermName = pn match case s: String => termName(s) case n: Name => n.toTermName diff --git a/compiler/src/dotty/tools/dotc/core/Flags.scala b/compiler/src/dotty/tools/dotc/core/Flags.scala index 85c436a29c2f..2c46f2c95924 100644 --- a/compiler/src/dotty/tools/dotc/core/Flags.scala +++ b/compiler/src/dotty/tools/dotc/core/Flags.scala @@ -22,7 +22,7 @@ object Flags { type Flag = opaques.Flag - extension on (x: FlagSet) { + extension (x: FlagSet) { def bits: Long = opaques.toBits(x) diff --git a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala index e9ed8d54887d..7fafb72c5e24 100644 --- a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -727,7 +727,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { } /** Print modifiers from symbols if tree has type, overriding the behavior in Trees. */ - def (mdef: untpd.DefTree).mods: untpd.Modifiers = + extension (mdef: untpd.DefTree) def mods: untpd.Modifiers = if mdef.hasType then Modifiers(mdef.symbol) else mdef.rawMods private def Modifiers(sym: Symbol): Modifiers = untpd.Modifiers( diff --git a/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala b/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala index 79bd6a661bb9..d8b791f7fe05 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala @@ -260,9 +260,10 @@ class ExtractSemanticDB extends Phase: case _ => None - private inline def (tpe: Types.Type) isAnnotatedByUnchecked(using Context) = tpe match - case Types.AnnotatedType(_, annot) => annot.symbol == defn.UncheckedAnnot - case _ => false + extension (tpe: Types.Type): + private inline def isAnnotatedByUnchecked(using Context) = tpe match + case Types.AnnotatedType(_, annot) => annot.symbol == defn.UncheckedAnnot + case _ => false def collectPats(pat: Tree): List[Tree] = @@ -282,11 +283,12 @@ class ExtractSemanticDB extends Phase: end PatternValDef - private def (tree: NamedDefTree) adjustedNameSpan(using Context): Span = - if tree.span.exists && tree.name.isAnonymousFunctionName || tree.name.isAnonymousClassName - Span(tree.span.point) - else - tree.nameSpan + extension (tree: NamedDefTree): + private def adjustedNameSpan(using Context): Span = + if tree.span.exists && tree.name.isAnonymousFunctionName || tree.name.isAnonymousClassName + Span(tree.span.point) + else + tree.nameSpan /** Add semanticdb name of the given symbol to string builder */ private def addSymName(b: StringBuilder, sym: Symbol)(using Context): Unit = @@ -496,12 +498,14 @@ class ExtractSemanticDB extends Phase: val start = if idx >= 0 then idx else span.start Span(start, start + sym.name.show.length, start) - private inline def (list: List[List[ValDef]]) isSingleArg = list match - case (_::Nil)::Nil => true - case _ => false + extension (list: List[List[ValDef]]): + private inline def isSingleArg = list match + case (_::Nil)::Nil => true + case _ => false - private def (tree: DefDef) isSetterDef(using Context): Boolean = - tree.name.isSetterName && tree.mods.is(Accessor) && tree.vparamss.isSingleArg + extension (tree: DefDef): + private def isSetterDef(using Context): Boolean = + tree.name.isSetterName && tree.mods.is(Accessor) && tree.vparamss.isSingleArg private def findGetters(ctorParams: Set[Names.TermName], body: List[Tree])(using Context): Map[Names.TermName, ValDef] = if ctorParams.isEmpty || body.isEmpty then @@ -525,26 +529,27 @@ class ExtractSemanticDB extends Phase: else limit Span(start max limit, end) - private extension on (span: Span): - def hasLength: Boolean = span.start != span.end - def zeroLength: Boolean = span.start == span.end + extension (span: Span): + private def hasLength: Boolean = span.start != span.end + private def zeroLength: Boolean = span.start == span.end /**Consume head while not an import statement. * Returns the rest of the list after the first import, or else the empty list */ - @tailrec - private def (body: List[Tree]) foreachUntilImport(op: Tree => Unit): List[Tree] = body match - case ((_: Import) :: rest) => rest - case stat :: rest => - op(stat) - rest.foreachUntilImport(op) - case Nil => Nil - - private def (sym: Symbol) adjustIfCtorTyparam(using Context) = - if sym.isType && sym.owner.exists && sym.owner.isConstructor - matchingMemberType(sym, sym.owner.owner) - else - sym + extension (body: List[Tree]): + @tailrec private def foreachUntilImport(op: Tree => Unit): List[Tree] = body match + case ((_: Import) :: rest) => rest + case stat :: rest => + op(stat) + rest.foreachUntilImport(op) + case Nil => Nil + + extension (sym: Symbol): + private def adjustIfCtorTyparam(using Context) = + if sym.isType && sym.owner.exists && sym.owner.isConstructor + matchingMemberType(sym, sym.owner.owner) + else + sym private inline def matchingMemberType(ctorTypeParam: Symbol, classSym: Symbol)(using Context) = classSym.info.member(ctorTypeParam.name).symbol diff --git a/compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala b/compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala index 2842c78bdbf2..5ffc6cc244a5 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala @@ -105,7 +105,7 @@ object Scala3: val setterName = sym.name.toTermName.setterName - inline def (t: Type) matchingType = t.paramInfoss match + extension (t: Type) inline def matchingType = t.paramInfoss match case (arg::Nil)::Nil => t.resultType == defn.UnitType && arg == sym.info case _ => false @@ -139,9 +139,10 @@ object Scala3: end LocalSymbol - private inline def (char: Char) isGlobalTerminal = (char: @switch) match - case '/' | '.' | '#' | ']' | ')' => true - case _ => false + extension (char: Char): + private inline def isGlobalTerminal = (char: @switch) match + case '/' | '.' | '#' | ']' | ')' => true + case _ => false extension StringOps on (symbol: String): diff --git a/compiler/src/dotty/tools/dotc/semanticdb/Tools.scala b/compiler/src/dotty/tools/dotc/semanticdb/Tools.scala index c1f3729f3a32..4a7e19308d7d 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/Tools.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/Tools.scala @@ -137,4 +137,5 @@ object Tools: sb.append(if occ.role.isReference then " -> " else " <- ").append(occ.symbol).nl end processOccurrence - private inline def (sb: StringBuilder) nl = sb.append(System.lineSeparator) + extension (sb: StringBuilder): + private inline def nl = sb.append(System.lineSeparator) diff --git a/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala b/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala index 590816f8ddf7..e1f701658db1 100644 --- a/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala +++ b/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala @@ -324,7 +324,7 @@ object ExplicitOuter { tpe } - def (sym: Symbol).isOuterParamAccessor(using Context): Boolean = + extension (sym: Symbol) def isOuterParamAccessor(using Context): Boolean = sym.is(ParamAccessor) && sym.name == nme.OUTER def outer(using Context): OuterOps = new OuterOps(ctx) diff --git a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala index be1d76dc642d..1271d8fdd240 100644 --- a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala +++ b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala @@ -238,7 +238,7 @@ class SymUtils(val self: Symbol) extends AnyVal { * all refinements for opaque types. */ def declaredSelfTypeAsSeenFrom(site: Type)(using Context) = - def (tp: Type).stripOpaques: Type = tp match + extension (tp: Type) def stripOpaques: Type = tp match case RefinedType(parent, name, _) if self.info.decl(name).symbol.isOpaqueAlias => parent.stripOpaques case _ => diff --git a/compiler/src/dotty/tools/dotc/transform/init/Effects.scala b/compiler/src/dotty/tools/dotc/transform/init/Effects.scala index 6340f5286a85..9b204c735397 100644 --- a/compiler/src/dotty/tools/dotc/transform/init/Effects.scala +++ b/compiler/src/dotty/tools/dotc/transform/init/Effects.scala @@ -61,7 +61,7 @@ object Effects { // ------------------ operations on effects ------------------ - def (eff: Effect) toEffs: Effects = Effects.empty + eff + extension (eff: Effect) def toEffs: Effects = Effects.empty + eff def asSeenFrom(eff: Effect, thisValue: Potential, currentClass: ClassSymbol, outer: Potentials)(implicit env: Env): Effects = trace(eff.show + " asSeenFrom " + thisValue.show + ", current = " + currentClass.show + ", outer = " + Potentials.show(outer), init, effs => show(effs.asInstanceOf[Effects])) { eff match { diff --git a/compiler/src/dotty/tools/dotc/transform/init/Potentials.scala b/compiler/src/dotty/tools/dotc/transform/init/Potentials.scala index 777969929d39..14022140e377 100644 --- a/compiler/src/dotty/tools/dotc/transform/init/Potentials.scala +++ b/compiler/src/dotty/tools/dotc/transform/init/Potentials.scala @@ -147,9 +147,9 @@ object Potentials { // ------------------ operations on potentials ------------------ - def (pot: Potential) toPots: Potentials = Potentials.empty + pot + extension (pot: Potential) def toPots: Potentials = Potentials.empty + pot - def (ps: Potentials) select (symbol: Symbol, source: Tree)(using Context): Summary = + extension (ps: Potentials) def select (symbol: Symbol, source: Tree)(using Context): Summary = ps.foldLeft(Summary.empty) { case ((pots, effs), pot) => // max potential length // TODO: it can be specified on a project basis via compiler options @@ -166,7 +166,7 @@ object Potentials { (pots + FieldReturn(pot, symbol)(source), effs + FieldAccess(pot, symbol)(source)) } - def (ps: Potentials) promote(source: Tree): Effects = ps.map(Promote(_)(source)) + extension (ps: Potentials) def promote(source: Tree): Effects = ps.map(Promote(_)(source)) def asSeenFrom(pot: Potential, thisValue: Potential, currentClass: ClassSymbol, outer: Potentials)(implicit env: Env): Potentials = trace(pot.show + " asSeenFrom " + thisValue.show + ", current = " + currentClass.show + ", outer = " + show(outer), init, pots => show(pots.asInstanceOf[Potentials])) { pot match { diff --git a/compiler/src/dotty/tools/dotc/transform/init/Summary.scala b/compiler/src/dotty/tools/dotc/transform/init/Summary.scala index 9e626547710c..fd62efc1cb4c 100644 --- a/compiler/src/dotty/tools/dotc/transform/init/Summary.scala +++ b/compiler/src/dotty/tools/dotc/transform/init/Summary.scala @@ -86,18 +86,18 @@ object Summary { s"([$pots], [$effs])" } - def (summary1: Summary) union (summary2: Summary): Summary = + extension (summary1: Summary) def union (summary2: Summary): Summary = (summary1._1 ++ summary2._1, summary1._2 ++ summary2._2) - def (summary: Summary) + (pot: Potential): Summary = + extension (summary: Summary) def + (pot: Potential): Summary = (summary._1 + pot, summary._2) - def (summary: Summary) + (eff: Effect): Summary = + extension (summary: Summary) def + (eff: Effect): Summary = (summary._1, summary._2 + eff) - def (summary: Summary) withPots (pots: Potentials): Summary = + extension (summary: Summary) def withPots (pots: Potentials): Summary = (summary._1 ++ pots, summary._2) - def (summary: Summary) withEffs (effs: Effects): Summary = + extension (summary: Summary) def withEffs (effs: Effects): Summary = (summary._1, summary._2 ++ effs) } diff --git a/compiler/src/dotty/tools/dotc/transform/init/Util.scala b/compiler/src/dotty/tools/dotc/transform/init/Util.scala index 58d05d63f573..6a315f0050c7 100644 --- a/compiler/src/dotty/tools/dotc/transform/init/Util.scala +++ b/compiler/src/dotty/tools/dotc/transform/init/Util.scala @@ -19,7 +19,7 @@ object Util { traceIndented(s"<== ${msg}", printer) } - def (symbol: Symbol) isInternal(using Context): Boolean = + extension (symbol: Symbol) def isInternal(using Context): Boolean = !symbol.defTree.isEmpty def resolve(cls: ClassSymbol, sym: Symbol)(using Context): Symbol = diff --git a/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala b/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala index 0bdb6d2507c6..16e8b9bc5c04 100644 --- a/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala +++ b/compiler/src/dotty/tools/dotc/typer/ImportSuggestions.scala @@ -266,7 +266,7 @@ trait ImportSuggestions: /** The `ref` parts of this list of pairs, discarding subsequent elements that * have the same String part. Elements are sorted by their String parts. */ - def (refs: List[(TermRef, String)]).distinctRefs(using Context): List[TermRef] = refs match + extension (refs: List[(TermRef, String)]) def distinctRefs(using Context): List[TermRef] = refs match case (ref, str) :: refs1 => ref :: refs1.dropWhile(_._2 == str).distinctRefs case Nil => @@ -276,7 +276,7 @@ trait ImportSuggestions: * `compare` is a partial order. If there's a tie, we take elements * in the order thy appear in the list. */ - def (refs: List[TermRef]).best(n: Int)(using Context): List[TermRef] = + extension (refs: List[TermRef]) def best(n: Int)(using Context): List[TermRef] = val top = new Array[TermRef](n) var filled = 0 val rest = new mutable.ListBuffer[TermRef] diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index b9546bb25746..30f7b64c8271 100644 --- a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala +++ b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala @@ -466,7 +466,7 @@ object RefChecks { def isImplemented(mbr: Symbol) = val mbrType = clazz.thisType.memberInfo(mbr) - def (sym: Symbol).isConcrete = sym.exists && !sym.is(Deferred) + extension (sym: Symbol) def isConcrete = sym.exists && !sym.is(Deferred) clazz.nonPrivateMembersNamed(mbr.name) .filterWithPredicate( impl => impl.symbol.isConcrete && mbrType.matchesLoosely(impl.info))