From 7f454a1dab41c0b669f85501ff3101b38968f81e Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 22 Jul 2020 10:05:40 +0200 Subject: [PATCH] Use extension methods --- .../dotty/tools/dotc/CompilationUnit.scala | 2 +- .../src/dotty/tools/dotc/ast/Desugar.scala | 2 +- .../src/dotty/tools/dotc/ast/TreeInfo.scala | 2 +- compiler/src/dotty/tools/dotc/ast/tpd.scala | 5 +-- .../dotc/classpath/ClassPathFactory.scala | 2 +- .../tools/dotc/classpath/FileUtils.scala | 4 +- .../dotc/classpath/ZipArchiveFileLookup.scala | 2 +- .../dotty/tools/dotc/config/Settings.scala | 2 +- .../src/dotty/tools/dotc/core/Contexts.scala | 4 +- .../dotty/tools/dotc/core/Decorators.scala | 42 +++++++++---------- .../src/dotty/tools/dotc/core/NameOps.scala | 7 ++-- .../tools/dotc/core/NullOpsDecorator.scala | 2 +- .../tools/dotc/core/SymDenotations.scala | 2 +- .../dotty/tools/dotc/core/SymbolLoaders.scala | 2 +- .../src/dotty/tools/dotc/core/Symbols.scala | 2 +- .../dotty/tools/dotc/core/TypeComparer.scala | 2 +- .../src/dotty/tools/dotc/core/Types.scala | 2 +- .../tools/dotc/core/tasty/TreeUnpickler.scala | 2 +- .../core/unpickleScala2/Scala2Unpickler.scala | 4 +- .../tools/dotc/interactive/Completion.scala | 4 +- .../tools/dotc/interactive/Interactive.scala | 2 +- .../dotty/tools/dotc/parsing/Parsers.scala | 3 +- .../src/dotty/tools/dotc/printing/Texts.scala | 4 +- .../dotty/tools/dotc/printing/package.scala | 6 +-- .../dotty/tools/dotc/reporting/Reporter.scala | 2 +- .../dotc/semanticdb/ExtractSemanticDB.scala | 2 +- .../dotty/tools/dotc/semanticdb/Scala3.scala | 2 +- .../dotc/transform/FullParameterization.scala | 2 +- .../dotty/tools/dotc/transform/SymUtils.scala | 11 ++--- .../tools/dotc/transform/TypeUtils.scala | 2 +- .../tools/dotc/transform/ValueClasses.scala | 2 +- .../src/dotty/tools/dotc/typer/Namer.scala | 4 +- .../tools/dotc/typer/QuotesAndSplices.scala | 2 +- .../src/dotty/tools/dotc/typer/Typer.scala | 2 +- compiler/src/dotty/tools/repl/Rendering.scala | 6 +-- compiler/src/dotty/tools/repl/results.scala | 9 ++-- .../tools/backend/jvm/AsmConverters.scala | 8 ++-- .../tools/backend/jvm/DottyBytecodeTest.scala | 4 +- .../dotc/parsing/ModifiersParsingTest.scala | 2 +- compiler/test/dotty/tools/repl/ReplTest.scala | 5 +-- .../tools/languageserver/WorksheetTest.scala | 2 +- tests/neg-with-compiler/Main.scala | 3 +- 42 files changed, 83 insertions(+), 98 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/CompilationUnit.scala b/compiler/src/dotty/tools/dotc/CompilationUnit.scala index ee6e64acc33b..02b30ce8d418 100644 --- a/compiler/src/dotty/tools/dotc/CompilationUnit.scala +++ b/compiler/src/dotty/tools/dotc/CompilationUnit.scala @@ -12,7 +12,7 @@ import tpd.{Tree, TreeTraverser} import typer.PrepareInlineable.InlineAccessors import typer.Nullables import transform.SymUtils._ -import core.Decorators.{given _} +import core.Decorators._ import config.SourceVersion class CompilationUnit protected (val source: SourceFile) { diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 7eca7b524bd2..9c27443f54cf 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -5,7 +5,7 @@ package ast import core._ import util.Spans._, Types._, Contexts._, Constants._, Names._, NameOps._, Flags._ import Symbols._, StdNames._, Trees._, Phases._, ContextOps._ -import Decorators.{given _}, transform.SymUtils._ +import Decorators._, transform.SymUtils._ import NameKinds.{UniqueName, EvidenceParamName, DefaultGetterName} import typer.{FrontEnd, Namer} import util.{Property, SourceFile, SourcePosition} diff --git a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala index 8eda55e42272..67ba61d4a444 100644 --- a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala +++ b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala @@ -831,7 +831,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] => /** Structural tree comparison (since == on trees is reference equality). * For the moment, only Ident, Select, Literal, Apply and TypeApply are supported */ - implicit class StructuralEqDeco(t1: Tree) { + extension (t1: Tree) { def === (t2: Tree)(using Context): Boolean = (t1, t2) match { case (t1: Ident, t2: Ident) => t1.symbol == t2.symbol diff --git a/compiler/src/dotty/tools/dotc/ast/tpd.scala b/compiler/src/dotty/tools/dotc/ast/tpd.scala index 3d55f224265a..b7748e975e28 100644 --- a/compiler/src/dotty/tools/dotc/ast/tpd.scala +++ b/compiler/src/dotty/tools/dotc/ast/tpd.scala @@ -9,7 +9,7 @@ import transform.TypeUtils._ import core._ import util.Spans._, Types._, Contexts._, Constants._, Names._, Flags._, NameOps._ import Symbols._, StdNames._, Annotations._, Trees._, Symbols._ -import Decorators.{given _}, DenotTransformers._ +import Decorators._, DenotTransformers._ import collection.{immutable, mutable} import util.{Property, SourceFile, NoSource} import NameKinds.{TempResultName, OuterSelectName} @@ -1111,12 +1111,11 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { !(sym.is(Method) && sym.info.isInstanceOf[MethodOrPoly]) // if is a method it is parameterless } - implicit class ListOfTreeDecorator(val xs: List[tpd.Tree]) extends AnyVal { + extension (xs: List[tpd.Tree]): def tpes: List[Type] = xs match { case x :: xs1 => x.tpe :: xs1.tpes case nil => Nil } - } /** A trait for loaders that compute trees. Currently implemented just by DottyUnpickler. */ trait TreeProvider { diff --git a/compiler/src/dotty/tools/dotc/classpath/ClassPathFactory.scala b/compiler/src/dotty/tools/dotc/classpath/ClassPathFactory.scala index 66ae5b1ceb1e..ac8b69381938 100644 --- a/compiler/src/dotty/tools/dotc/classpath/ClassPathFactory.scala +++ b/compiler/src/dotty/tools/dotc/classpath/ClassPathFactory.scala @@ -4,7 +4,7 @@ package dotty.tools.dotc.classpath import dotty.tools.io.{AbstractFile, VirtualDirectory} -import FileUtils.AbstractFileOps +import FileUtils._ import dotty.tools.io.ClassPath import dotty.tools.dotc.core.Contexts._ diff --git a/compiler/src/dotty/tools/dotc/classpath/FileUtils.scala b/compiler/src/dotty/tools/dotc/classpath/FileUtils.scala index 9046b8861c0a..d39ca0c11d12 100644 --- a/compiler/src/dotty/tools/dotc/classpath/FileUtils.scala +++ b/compiler/src/dotty/tools/dotc/classpath/FileUtils.scala @@ -12,7 +12,7 @@ import dotty.tools.io.AbstractFile * Common methods related to Java files and abstract files used in the context of classpath */ object FileUtils { - implicit class AbstractFileOps(val file: AbstractFile) extends AnyVal { + extension (file: AbstractFile) { def isPackage: Boolean = file.isDirectory && mayBeValidPackage(file.name) def isClass: Boolean = !file.isDirectory && file.hasExtension("class") && !file.name.endsWith("$class.class") @@ -30,7 +30,7 @@ object FileUtils { def toURLs(default: => Seq[URL] = Seq.empty): Seq[URL] = if (file.file == null) default else Seq(file.toURL) } - implicit class FileOps(val file: JFile) extends AnyVal { + extension (file: JFile) { def isPackage: Boolean = file.isDirectory && mayBeValidPackage(file.getName) def isClass: Boolean = file.isFile && file.getName.endsWith(".class") && !file.getName.endsWith("$class.class") diff --git a/compiler/src/dotty/tools/dotc/classpath/ZipArchiveFileLookup.scala b/compiler/src/dotty/tools/dotc/classpath/ZipArchiveFileLookup.scala index 355c9861e47b..35a4c89c3f72 100644 --- a/compiler/src/dotty/tools/dotc/classpath/ZipArchiveFileLookup.scala +++ b/compiler/src/dotty/tools/dotc/classpath/ZipArchiveFileLookup.scala @@ -7,7 +7,7 @@ import java.io.File import java.net.URL import dotty.tools.io.{ AbstractFile, FileZipArchive } -import FileUtils.AbstractFileOps +import FileUtils._ import dotty.tools.io.{ClassPath, ClassRepresentation} /** diff --git a/compiler/src/dotty/tools/dotc/config/Settings.scala b/compiler/src/dotty/tools/dotc/config/Settings.scala index 2cbe0ac3aa2e..f039f68591d6 100644 --- a/compiler/src/dotty/tools/dotc/config/Settings.scala +++ b/compiler/src/dotty/tools/dotc/config/Settings.scala @@ -184,7 +184,7 @@ object Settings { } object Setting { - implicit class SettingDecorator[T](val setting: Setting[T]) extends AnyVal { + extension [T](setting: Setting[T]) { def value(using Context): T = setting.valueIn(ctx.settingsState) def update(x: T)(using Context): SettingsState = setting.updateIn(ctx.settingsState, x) def isDefault(using Context): Boolean = setting.isDefaultIn(ctx.settingsState) diff --git a/compiler/src/dotty/tools/dotc/core/Contexts.scala b/compiler/src/dotty/tools/dotc/core/Contexts.scala index 29b82e29c97b..941078a0d82e 100644 --- a/compiler/src/dotty/tools/dotc/core/Contexts.scala +++ b/compiler/src/dotty/tools/dotc/core/Contexts.scala @@ -678,7 +678,7 @@ object Contexts { end ops // TODO: Fix issue when converting ModeChanges and FreshModeChanges to extension givens - implicit class ModeChanges(val c: Context) extends AnyVal { + extension (c: Context) { final def withModeBits(mode: Mode): Context = if (mode != c.mode) c.fresh.setMode(mode) else c @@ -686,7 +686,7 @@ object Contexts { final def retractMode(mode: Mode): Context = withModeBits(c.mode &~ mode) } - implicit class FreshModeChanges(val c: FreshContext) extends AnyVal { + extension (c: FreshContext) { final def addMode(mode: Mode): c.type = c.setMode(c.mode | mode) final def retractMode(mode: Mode): c.type = c.setMode(c.mode &~ mode) } diff --git a/compiler/src/dotty/tools/dotc/core/Decorators.scala b/compiler/src/dotty/tools/dotc/core/Decorators.scala index 03a216a28949..a02cf7224019 100644 --- a/compiler/src/dotty/tools/dotc/core/Decorators.scala +++ b/compiler/src/dotty/tools/dotc/core/Decorators.scala @@ -28,7 +28,7 @@ object Decorators { case s: String => termName(s) case n: Name => n.toTermName - implicit class StringDecorator(val s: String) extends AnyVal { + extension (s: String): def splitWhere(f: Char => Boolean, doDropIndex: Boolean): Option[(String, String)] = { def splitAt(idx: Int, doDropIndex: Boolean): Option[(String, String)] = if (idx == -1) None @@ -36,12 +36,11 @@ object Decorators { splitAt(s.indexWhere(f), doDropIndex) } - } /** Implements a findSymbol method on iterators of Symbols that * works like find but avoids Option, replacing None with NoSymbol. */ - implicit class SymbolIteratorDecorator(val it: Iterator[Symbol]) extends AnyVal { + extension (it: Iterator[Symbol]): final def findSymbol(p: Symbol => Boolean): Symbol = { while (it.hasNext) { val sym = it.next() @@ -49,7 +48,6 @@ object Decorators { } NoSymbol } - } final val MaxFilterRecursions = 1000 @@ -161,29 +159,27 @@ object Decorators { def & (ys: List[T]): List[T] = xs filter (ys contains _) } - given ListOfListDecorator as AnyRef: - extension [T, U](xss: List[List[T]]): - def nestedMap(f: T => U): List[List[U]] = - xss.map(_.map(f)) - def nestedMapConserve(f: T => U): List[List[U]] = - xss.mapconserve(_.mapconserve(f)) - def nestedZipWithConserve(yss: List[List[U]])(f: (T, U) => T): List[List[T]] = - xss.zipWithConserve(yss)((xs, ys) => xs.zipWithConserve(ys)(f)) - end extension - - implicit class TextToString(val text: Text) extends AnyVal { + extension [T, U](xss: List[List[T]]): + def nestedMap(f: T => U): List[List[U]] = + xss.map(_.map(f)) + def nestedMapConserve(f: T => U): List[List[U]] = + xss.mapconserve(_.mapconserve(f)) + def nestedZipWithConserve(yss: List[List[U]])(f: (T, U) => T): List[List[T]] = + xss.zipWithConserve(yss)((xs, ys) => xs.zipWithConserve(ys)(f)) + end extension + + extension (text: Text): def show(using Context): String = text.mkString(ctx.settings.pageWidth.value, ctx.settings.printLines.value) - } /** Test whether a list of strings representing phases contains * a given phase. See [[config.CompilerCommand#explainAdvanced]] for the * exact meaning of "contains" here. */ - implicit class PhaseListDecorator(val names: List[String]) extends AnyVal { + extension (names: List[String]) { def containsPhase(phase: Phase): Boolean = names.nonEmpty && { phase match { - case phase: MegaPhase => phase.miniPhases.exists(containsPhase) + case phase: MegaPhase => phase.miniPhases.exists(x => names.containsPhase(x)) case _ => names exists { name => name == "all" || { @@ -197,7 +193,7 @@ object Decorators { } } - implicit class reportDeco[T](x: T) extends AnyVal { + extension [T](x: T) { def reporting( op: WrappedResult[T] ?=> String, printer: config.Printers.Printer = config.Printers.default): T = { @@ -206,7 +202,7 @@ object Decorators { } } - implicit class genericDeco[T](val x: T) extends AnyVal { + extension [T](x: T) { def assertingErrorsReported(using Context): T = { assert(ctx.reporter.errorsReported) x @@ -217,7 +213,7 @@ object Decorators { } } - implicit class StringInterpolators(val sc: StringContext) extends AnyVal { + extension (sc: StringContext) { /** General purpose string formatting */ def i(args: Any*)(using Context): String = new StringFormatter(sc).assemble(args) @@ -235,8 +231,8 @@ object Decorators { explained(em(args: _*)) } - implicit class ArrayInterpolator[T <: AnyRef](val arr: Array[T]) extends AnyVal { + extension [T <: AnyRef](arr: Array[T]): def binarySearch(x: T): Int = java.util.Arrays.binarySearch(arr.asInstanceOf[Array[Object]], x) - } + } diff --git a/compiler/src/dotty/tools/dotc/core/NameOps.scala b/compiler/src/dotty/tools/dotc/core/NameOps.scala index 07e1d6963b22..f55b2c808259 100644 --- a/compiler/src/dotty/tools/dotc/core/NameOps.scala +++ b/compiler/src/dotty/tools/dotc/core/NameOps.scala @@ -7,6 +7,7 @@ import Names._, StdNames._, Contexts._, Symbols._, Flags._, NameKinds._, Types._ import scala.internal.Chars import Chars.isOperatorPart import Definitions._ +import nme._ object NameOps { @@ -49,8 +50,7 @@ object NameOps { } } - implicit class NameDecorator[N <: Name](private val name: N) extends AnyVal { - import nme._ + extension [N <: Name](name: N) { def testSimple(f: SimpleName => Boolean): Boolean = name match { case name: SimpleName => f(name) @@ -268,8 +268,7 @@ object NameOps { } } - implicit class TermNameDecorator(private val name: TermName) extends AnyVal { - import nme._ + extension (name: TermName) { def setterName: TermName = name.exclude(FieldName) ++ str.SETTER_SUFFIX diff --git a/compiler/src/dotty/tools/dotc/core/NullOpsDecorator.scala b/compiler/src/dotty/tools/dotc/core/NullOpsDecorator.scala index 1f138213dde4..878c52d5f32b 100644 --- a/compiler/src/dotty/tools/dotc/core/NullOpsDecorator.scala +++ b/compiler/src/dotty/tools/dotc/core/NullOpsDecorator.scala @@ -7,7 +7,7 @@ import dotty.tools.dotc.core.Types._ /** Defines operations on nullable types. */ object NullOpsDecorator { - implicit class NullOps(val self: Type) { + extension (self: Type) { /** Is this type exactly `UncheckedNull` (no vars, aliases, refinements etc allowed)? */ def isUncheckedNullType(using Context): Boolean = { assert(ctx.explicitNulls) diff --git a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala index 70525007707a..54d48a7c2e06 100644 --- a/compiler/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/compiler/src/dotty/tools/dotc/core/SymDenotations.scala @@ -10,7 +10,7 @@ import Constants.Constant import TypeApplications.TypeParamInfo import Scopes.Scope import dotty.tools.io.AbstractFile -import Decorators.SymbolIteratorDecorator +import Decorators._ import ast._ import ast.Trees.{LambdaTypeTree, TypeBoundsTree, ValDef, TypeDef} import Trees.Literal diff --git a/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala b/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala index 0755b3ae5fc0..3965ad2735ae 100644 --- a/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala +++ b/compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala @@ -9,7 +9,7 @@ import config.Config import Contexts._, Symbols._, Flags._, SymDenotations._, Types._, Scopes._, Names._ import NameOps._ import StdNames.str -import Decorators.StringInterpolators +import Decorators._ import classfile.ClassfileParser import util.Stats import Decorators._ diff --git a/compiler/src/dotty/tools/dotc/core/Symbols.scala b/compiler/src/dotty/tools/dotc/core/Symbols.scala index ab3439971a0b..f761f4f9c557 100644 --- a/compiler/src/dotty/tools/dotc/core/Symbols.scala +++ b/compiler/src/dotty/tools/dotc/core/Symbols.scala @@ -454,7 +454,7 @@ object Symbols { NoDenotation // force it in order to set `denot` field of NoSymbol - implicit class Copier[N <: Name](sym: Symbol { type ThisName = N })(using Context) { + extension [N <: Name](sym: Symbol { type ThisName = N })(using Context) { /** Copy a symbol, overriding selective fields. * Note that `coord` and `associatedFile` will be set from the fields in `owner`, not * the fields in `sym`. diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index bf569c708759..4ba902218ee5 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -22,7 +22,7 @@ import scala.util.control.NonFatal import typer.ProtoTypes.constrained import typer.Applications.productSelectorTypes import reporting.trace -import NullOpsDecorator.NullOps +import NullOpsDecorator._ /** Provides methods to compare types. */ diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 14e40c911935..1432c56914ec 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -5650,7 +5650,7 @@ object Types { implicit def decorateTypeApplications(tpe: Type): TypeApplications = new TypeApplications(tpe) - implicit class typeListDeco(val tps1: List[Type]) extends AnyVal { + extension (tps1: List[Type]) { @tailrec def hashIsStable: Boolean = tps1.isEmpty || tps1.head.hashIsStable && tps1.tail.hashIsStable @tailrec def equalElements(tps2: List[Type], bs: BinderPairs): Boolean = diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index b5bf7128d552..9ebee7935cc6 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -27,7 +27,7 @@ import util.Spans._ import util.SourceFile import ast.{TreeTypeMap, Trees, tpd, untpd} import Trees._ -import Decorators.{given _} +import Decorators._ import transform.SymUtils._ import dotty.tools.tasty.{TastyBuffer, TastyReader} diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index 48acfa480070..0cb50e868d01 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -596,9 +596,9 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas else tp1 if (denot.isConstructor) addConstructorTypeParams(denot) if (atEnd) - assert(!denot.isSuperAccessor, denot) + assert(!denot.symbol.isSuperAccessor, denot) else { - assert(denot.is(ParamAccessor) || denot.isSuperAccessor, denot) + assert(denot.is(ParamAccessor) || denot.symbol.isSuperAccessor, denot) def disambiguate(alt: Symbol) = // !!! DEBUG trace.onDebug(s"disambiguating ${denot.info} =:= ${denot.owner.thisType.memberInfo(alt)} ${denot.owner}") { denot.info matches denot.owner.thisType.memberInfo(alt) diff --git a/compiler/src/dotty/tools/dotc/interactive/Completion.scala b/compiler/src/dotty/tools/dotc/interactive/Completion.scala index f0ab6d176229..79c4f52fb0ba 100644 --- a/compiler/src/dotty/tools/dotc/interactive/Completion.scala +++ b/compiler/src/dotty/tools/dotc/interactive/Completion.scala @@ -7,12 +7,12 @@ import dotty.tools.dotc.ast.untpd import dotty.tools.dotc.config.Printers.interactiv import dotty.tools.dotc.core.Contexts._ import dotty.tools.dotc.core.CheckRealizable -import dotty.tools.dotc.core.Decorators.StringInterpolators +import dotty.tools.dotc.core.Decorators._ import dotty.tools.dotc.core.Denotations.SingleDenotation import dotty.tools.dotc.core.Flags._ import dotty.tools.dotc.core.Names.{Name, TermName} import dotty.tools.dotc.core.NameKinds.SimpleNameKind -import dotty.tools.dotc.core.NameOps.NameDecorator +import dotty.tools.dotc.core.NameOps._ import dotty.tools.dotc.core.Symbols.{NoSymbol, Symbol, defn} import dotty.tools.dotc.core.Scopes import dotty.tools.dotc.core.StdNames.{nme, tpnme} diff --git a/compiler/src/dotty/tools/dotc/interactive/Interactive.scala b/compiler/src/dotty/tools/dotc/interactive/Interactive.scala index a88f9f80c15d..81abc54666b8 100644 --- a/compiler/src/dotty/tools/dotc/interactive/Interactive.scala +++ b/compiler/src/dotty/tools/dotc/interactive/Interactive.scala @@ -9,7 +9,7 @@ import ast.{NavigateAST, Trees, tpd, untpd} import core._ import Decorators._, ContextOps._ import Contexts._, Flags._, Names._, NameOps._, Symbols._, Trees._, Types._ -import transform.SymUtils.decorateSymbol +import transform.SymUtils._ import util.Spans._, util.SourceFile, util.SourcePosition import core.Denotations.SingleDenotation import NameKinds.SimpleNameKind diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 943fe2603a72..398921a3cb04 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -64,12 +64,11 @@ object Parsers { val Spliced = 2 } - private implicit class AddDeco(val buf: ListBuffer[Tree]) extends AnyVal { + extension (buf: ListBuffer[Tree]): def +++=(x: Tree) = x match { case x: Thicket => buf ++= x.trees case x => buf += x } - } /** The parse starting point depends on whether the source file is self-contained: * if not, the AST will be supplemented. diff --git a/compiler/src/dotty/tools/dotc/printing/Texts.scala b/compiler/src/dotty/tools/dotc/printing/Texts.scala index 56a4218b0f87..32556b17c049 100644 --- a/compiler/src/dotty/tools/dotc/printing/Texts.scala +++ b/compiler/src/dotty/tools/dotc/printing/Texts.scala @@ -168,9 +168,9 @@ object Texts { /** The given texts `xs`, each on a separate line */ def lines(xs: Traversable[Text]): Vertical = Vertical(xs.toList.reverse) - implicit class textDeco(text: => Text) { + extension (text: => Text): def provided(cond: Boolean): Text = if (cond) text else Str("") - } + } case class Str(s: String, lineRange: LineRange = EmptyLineRange) extends Text { diff --git a/compiler/src/dotty/tools/dotc/printing/package.scala b/compiler/src/dotty/tools/dotc/printing/package.scala index 246bbd206d5e..5457fd209bf5 100644 --- a/compiler/src/dotty/tools/dotc/printing/package.scala +++ b/compiler/src/dotty/tools/dotc/printing/package.scala @@ -22,8 +22,8 @@ package object printing { val XprintMode: Key[Unit] = new Key /** @pre `nel` is non-empty list */ - private[printing] implicit class ListOps[A](val nel: List[A]) extends AnyVal { - def intersperse(a: A): List[A] = + extension [A](nel: List[A]): + private[printing] def intersperse(a: A): List[A] = nel.flatMap(a :: _ :: Nil).tail - } + } diff --git a/compiler/src/dotty/tools/dotc/reporting/Reporter.scala b/compiler/src/dotty/tools/dotc/reporting/Reporter.scala index 47464eb43b00..c7da7d9f5810 100644 --- a/compiler/src/dotty/tools/dotc/reporting/Reporter.scala +++ b/compiler/src/dotty/tools/dotc/reporting/Reporter.scala @@ -5,7 +5,7 @@ package reporting import scala.annotation.internal.sharable import core.Contexts._ -import core.Decorators.PhaseListDecorator +import core.Decorators._ import collection.mutable import core.Mode import dotty.tools.dotc.core.Symbols.{Symbol, NoSymbol} diff --git a/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala b/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala index d8b791f7fe05..a3c4c73ce732 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala @@ -20,7 +20,7 @@ import java.nio.file.Paths import PartialFunction.condOpt import ast.untpd.{given _} -import NameOps.{given _} +import NameOps._ import scala.annotation.{ threadUnsafe => tu, tailrec } diff --git a/compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala b/compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala index 3e9a0356f607..87030ece370e 100644 --- a/compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala +++ b/compiler/src/dotty/tools/dotc/semanticdb/Scala3.scala @@ -17,7 +17,7 @@ import scala.annotation.switch object Scala3: import Symbols._ - import core.NameOps.{given _} + import core.NameOps._ @sharable private val unicodeEscape = raw"\$$u(\p{XDigit}{4})".r @sharable private val locals = raw"local(\d+)".r diff --git a/compiler/src/dotty/tools/dotc/transform/FullParameterization.scala b/compiler/src/dotty/tools/dotc/transform/FullParameterization.scala index e9b0b228502f..fa8e39eb6c1e 100644 --- a/compiler/src/dotty/tools/dotc/transform/FullParameterization.scala +++ b/compiler/src/dotty/tools/dotc/transform/FullParameterization.scala @@ -5,7 +5,7 @@ import core._ import Types._ import Contexts._ import Symbols._ -import Decorators.{given _} +import Decorators._ import TypeUtils._ import StdNames.nme import NameOps._ diff --git a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala index e04915e8883c..28395538d825 100644 --- a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala +++ b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala @@ -19,15 +19,8 @@ import language.implicitConversions import scala.annotation.tailrec object SymUtils { - implicit def decorateSymbol(sym: Symbol): SymUtils = new SymUtils(sym) - implicit def decorateSymDenot(d: SymDenotation): SymUtils = new SymUtils(d.symbol) -} -/** A decorator that provides methods on symbols - * that are needed in the transformer pipeline. - */ -class SymUtils(val self: Symbol) extends AnyVal { - import SymUtils._ + extension (self: Symbol) { /** All traits implemented by a class or trait except for those inherited through the superclass. */ def directlyInheritedTraits(using Context): List[ClassSymbol] = { @@ -255,4 +248,6 @@ class SymUtils(val self: Symbol) extends AnyVal { case _ => tp self.asClass.givenSelfType.stripOpaques.asSeenFrom(site, self) + + } } diff --git a/compiler/src/dotty/tools/dotc/transform/TypeUtils.scala b/compiler/src/dotty/tools/dotc/transform/TypeUtils.scala index d3cec855eafe..c282880ca6b6 100644 --- a/compiler/src/dotty/tools/dotc/transform/TypeUtils.scala +++ b/compiler/src/dotty/tools/dotc/transform/TypeUtils.scala @@ -13,7 +13,7 @@ object TypeUtils { /** A decorator that provides methods on types * that are needed in the transformer pipeline. */ - implicit class TypeUtilsOps(val self: Type) extends AnyVal { + extension (self: Type) { def isErasedValueType(using Context): Boolean = self.isInstanceOf[ErasedValueType] diff --git a/compiler/src/dotty/tools/dotc/transform/ValueClasses.scala b/compiler/src/dotty/tools/dotc/transform/ValueClasses.scala index addaa2124233..c6fe838bd26e 100644 --- a/compiler/src/dotty/tools/dotc/transform/ValueClasses.scala +++ b/compiler/src/dotty/tools/dotc/transform/ValueClasses.scala @@ -29,7 +29,7 @@ object ValueClasses { d.isRealMethod && isDerivedValueClass(d.owner) && !d.isConstructor && - !d.isSuperAccessor && + !d.symbol.isSuperAccessor && !d.is(Macro) } diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 368b9024e7a2..c1afdb22b08d 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -6,7 +6,7 @@ import core._ import ast._ import Trees._, StdNames._, Scopes._, Denotations._, NamerOps._, ContextOps._ import Contexts._, Symbols._, Types._, SymDenotations._, Names._, NameOps._, Flags._ -import Decorators.{given _}, Comments.{_, given _} +import Decorators._, Comments.{_, given _} import NameKinds.DefaultGetterName import TypeApplications.TypeParamInfo import ast.desugar, ast.desugar._ @@ -14,7 +14,7 @@ import ProtoTypes._ import util.Spans._ import util.Property import collection.mutable -import tpd.ListOfTreeDecorator +import tpd.tpes import Variances.alwaysInvariant import config.{Config, Feature} import config.Printers.typr diff --git a/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala b/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala index 77c9735ba27f..4f4d3f71b3aa 100644 --- a/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala +++ b/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala @@ -16,7 +16,7 @@ import dotty.tools.dotc.core.StdNames._ import dotty.tools.dotc.core.Symbols._ import dotty.tools.dotc.core.Types._ import dotty.tools.dotc.reporting._ -import dotty.tools.dotc.transform.SymUtils.decorateSymbol +import dotty.tools.dotc.transform.SymUtils._ import dotty.tools.dotc.typer.Implicits._ import dotty.tools.dotc.typer.Inferencing._ import dotty.tools.dotc.typer.ProtoTypes._ diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 03c4cb29d0f2..020a708af9ec 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -21,7 +21,7 @@ import NameKinds._ import NamerOps._ import ContextOps._ import Flags._ -import Decorators.{given _} +import Decorators._ import ErrorReporting._ import Checking._ import Inferencing._ diff --git a/compiler/src/dotty/tools/repl/Rendering.scala b/compiler/src/dotty/tools/repl/Rendering.scala index 4406dbf1e4fc..00d489d08391 100644 --- a/compiler/src/dotty/tools/repl/Rendering.scala +++ b/compiler/src/dotty/tools/repl/Rendering.scala @@ -12,7 +12,7 @@ import dotc.core.Flags import dotc.core.Flags._ import dotc.core.Symbols.{Symbol, defn} import dotc.core.StdNames.str -import dotc.core.NameOps.NameDecorator +import dotc.core.NameOps._ import dotc.printing.ReplPrinter import dotc.reporting.{MessageRendering, Message, Diagnostic} import dotc.util.SourcePosition @@ -142,11 +142,11 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None) { object Rendering { - implicit class ShowUser(val s: Symbol) extends AnyVal { + extension (s: Symbol): def showUser(using Context): String = { val printer = new ReplPrinter(ctx) val text = printer.dclText(s) text.mkString(ctx.settings.pageWidth.value, ctx.settings.printLines.value) } - } + } diff --git a/compiler/src/dotty/tools/repl/results.scala b/compiler/src/dotty/tools/repl/results.scala index 032159dc910a..9f1c3917e805 100644 --- a/compiler/src/dotty/tools/repl/results.scala +++ b/compiler/src/dotty/tools/repl/results.scala @@ -14,11 +14,10 @@ object results { /** Result is a type alias for an Either with left value `Errors` */ type Result[+A] = scala.util.Either[Errors, A] - implicit class ResultConversionA[A](val a: A) extends AnyVal { + extension [A](a: A): def result: Result[A] = scala.util.Right(a) - } - implicit class ResultConversionErr(val xs: Errors) extends AnyVal { - def errors[A]: Result[A] = scala.util.Left(xs) - } + extension [A](xs: Errors): + def errors: Result[A] = scala.util.Left(xs) + } diff --git a/compiler/test/dotty/tools/backend/jvm/AsmConverters.scala b/compiler/test/dotty/tools/backend/jvm/AsmConverters.scala index 27cf4d31ea3a..17b5e892ae0f 100644 --- a/compiler/test/dotty/tools/backend/jvm/AsmConverters.scala +++ b/compiler/test/dotty/tools/backend/jvm/AsmConverters.scala @@ -20,7 +20,7 @@ object ASMConverters { def convertMethod(meth: t.MethodNode): Method = new AsmToScala(meth).method - implicit class RichInstructionLists(val self: List[Instruction]) extends AnyVal { + extension (self: List[Instruction]) { def === (other: List[Instruction]) = equivalentBytecode(self, other) def dropLinesFrames = self.filterNot(i => i.isInstanceOf[LineNumber] || i.isInstanceOf[FrameEntry]) @@ -33,13 +33,13 @@ object ASMConverters { case _ => Set.empty } - def dropStaleLabels = { + def dropStaleLabels: List[Instruction] = { val definedLabels: Set[Instruction] = self.filter(_.isInstanceOf[Label]).toSet - val usedLabels: Set[Instruction] = self.iterator.flatMap(referencedLabels).toSet + val usedLabels: Set[Instruction] = self.iterator.flatMap(self.referencedLabels(_)).toSet self.filterNot(definedLabels diff usedLabels) } - def dropNonOp = dropLinesFrames.dropStaleLabels + def dropNonOp: List[Instruction] = dropLinesFrames.dropStaleLabels def summary: List[Any] = dropNonOp map { case i: Invoke => i.name diff --git a/compiler/test/dotty/tools/backend/jvm/DottyBytecodeTest.scala b/compiler/test/dotty/tools/backend/jvm/DottyBytecodeTest.scala index 54e719808133..f6887fc3d459 100644 --- a/compiler/test/dotty/tools/backend/jvm/DottyBytecodeTest.scala +++ b/compiler/test/dotty/tools/backend/jvm/DottyBytecodeTest.scala @@ -214,8 +214,6 @@ trait DottyBytecodeTest { } } object DottyBytecodeTest { - implicit class listStringLines[T](val l: List[T]) extends AnyVal { - def stringLines = l.mkString("\n") - } + extension [T](l: List[T]) def stringLines = l.mkString("\n") } diff --git a/compiler/test/dotty/tools/dotc/parsing/ModifiersParsingTest.scala b/compiler/test/dotty/tools/dotc/parsing/ModifiersParsingTest.scala index edb29b855e65..d4338f6f3664 100644 --- a/compiler/test/dotty/tools/dotc/parsing/ModifiersParsingTest.scala +++ b/compiler/test/dotty/tools/dotc/parsing/ModifiersParsingTest.scala @@ -21,7 +21,7 @@ object ModifiersParsingTest { stats match { case List(stat) => stat; case stats => Thicket(stats) } } - implicit class TreeDeco(val code: Tree) extends AnyVal { + extension (code: Tree) { def firstConstrValDef: ValDef = code match { case d.TypeDef(_, d.Template(constr, _, _, _)) => constr.vparamss.head.head diff --git a/compiler/test/dotty/tools/repl/ReplTest.scala b/compiler/test/dotty/tools/repl/ReplTest.scala index de1e67861fac..45e47c72cd73 100644 --- a/compiler/test/dotty/tools/repl/ReplTest.scala +++ b/compiler/test/dotty/tools/repl/ReplTest.scala @@ -45,9 +45,8 @@ class ReplTest(withStaging: Boolean = false, out: ByteArrayOutputStream = new By def fromInitialState[A](op: State => A): A = op(initialState) - implicit class TestingState(state: State) { - def andThen[A](op: State => A): A = op(state) - } + extension [A](state: State): + def andThen(op: State => A): A = op(state) def scripts(path: String): Array[JFile] = { val dir = new JFile(getClass.getResource(path).getPath) diff --git a/language-server/test/dotty/tools/languageserver/WorksheetTest.scala b/language-server/test/dotty/tools/languageserver/WorksheetTest.scala index 43db599358f5..d2e09060da9a 100644 --- a/language-server/test/dotty/tools/languageserver/WorksheetTest.scala +++ b/language-server/test/dotty/tools/languageserver/WorksheetTest.scala @@ -4,7 +4,7 @@ import org.junit.Test import org.eclipse.lsp4j.{CompletionItemKind, DocumentHighlightKind, SymbolKind} import dotty.tools.dotc.core.StdNames.nme.WorksheetWrapper -import dotty.tools.dotc.core.NameOps.NameDecorator +import dotty.tools.dotc.core.NameOps._ import dotty.tools.languageserver.util.Code._ import dotty.tools.languageserver.util.embedded.CodeMarker diff --git a/tests/neg-with-compiler/Main.scala b/tests/neg-with-compiler/Main.scala index 24a94d654b58..b3b817284e4f 100644 --- a/tests/neg-with-compiler/Main.scala +++ b/tests/neg-with-compiler/Main.scala @@ -6,6 +6,7 @@ package dotty.tools package dotc import core.Contexts.Context +import config.Settings.Setting._ object Main extends Driver { def resident(compiler: Compiler): Unit = unsupported("resident") /*loop { line => @@ -17,7 +18,7 @@ object Main extends Driver { override def newCompiler(): Compiler = new Compiler override def doCompile(compiler: Compiler, fileNames: List[String])(implicit ctx: Context): Unit = { - if (new config.Settings.Setting.SettingDecorator(ctx.base.settings.resident).value) resident(compiler) // error + if (ctx.base.settings.resident.value) resident(compiler) // error else super.doCompile(compiler,123) // error: type mismatch } }