diff --git a/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala b/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala index 7688a7ae902f..088fbc9d2145 100644 --- a/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala +++ b/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala @@ -518,7 +518,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma * @see https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.3.4 */ def getGenericSignature(sym: Symbol, owner: Symbol): String = { - ctx.atPhase(ctx.erasurePhase) { implicit ctx => + ctx.atPhase(ctx.erasurePhase) { val memberTpe = if (sym.is(Flags.Method)) sym.denot.info else owner.denot.thisType.memberInfo(sym) @@ -533,7 +533,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma // But for now, just like we did in mixin, we just avoid writing a wrong generic signature // (one that doesn't erase to the actual signature). See run/t3452b for a test case. - val memberTpe = ctx.atPhase(ctx.erasurePhase) { implicit ctx => moduleClass.denot.thisType.memberInfo(sym) } + val memberTpe = ctx.atPhase(ctx.erasurePhase) { moduleClass.denot.thisType.memberInfo(sym) } val erasedMemberType = TypeErasure.erasure(memberTpe) if (erasedMemberType =:= sym.denot.info) getGenericSignature(sym, moduleClass, memberTpe).orNull @@ -782,7 +782,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma private def definedClasses(phase: Phase) = if (sym.isDefinedInCurrentRun) - ctx.atPhase(phase) { implicit ctx => + ctx.atPhase(phase) { toDenot(sym).info.decls.filter(_.isClass) } else Nil @@ -835,13 +835,13 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma * such objects. */ def isTopLevelModuleClass: Boolean = sym.isModuleClass && - ctx.atPhase(ctx.flattenPhase) { implicit ctx => + ctx.atPhase(ctx.flattenPhase) { toDenot(sym).owner.is(Flags.PackageClass) } def addRemoteRemoteExceptionAnnotation: Unit = () - def samMethod(): Symbol = ctx.atPhase(ctx.erasurePhase) { implicit ctx => + def samMethod(): Symbol = ctx.atPhase(ctx.erasurePhase) { toDenot(sym).info.abstractTermMembers.toList match { case x :: Nil => x.symbol case Nil => abort(s"${sym.show} is not a functional interface. It doesn't have abstract methods") diff --git a/compiler/src/dotty/tools/backend/jvm/GenBCode.scala b/compiler/src/dotty/tools/backend/jvm/GenBCode.scala index f2ddc71c60d1..050ea39e4394 100644 --- a/compiler/src/dotty/tools/backend/jvm/GenBCode.scala +++ b/compiler/src/dotty/tools/backend/jvm/GenBCode.scala @@ -162,8 +162,8 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter val (cl1, cl2) = if (classSymbol.effectiveName.toString < dupClassSym.effectiveName.toString) (classSymbol, dupClassSym) else (dupClassSym, classSymbol) - ctx.atPhase(ctx.typerPhase) { implicit ctx => - ctx.warning(s"${cl1.show} differs only in case from ${cl2.showLocated}. " + + ctx.atPhase(ctx.typerPhase) { + the[Context].warning(s"${cl1.show} differs only in case from ${cl2.showLocated}. " + "Such classes will overwrite one another on case-insensitive filesystems.", cl1.sourcePos) } } @@ -263,7 +263,7 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter // ----------- compiler and sbt's callbacks - val (fullClassName, isLocal) = ctx.atPhase(ctx.sbtExtractDependenciesPhase) { implicit ctx => + val (fullClassName, isLocal) = ctx.atPhase(ctx.sbtExtractDependenciesPhase) { (ExtractDependencies.classNameAsString(claszSymbol), claszSymbol.isLocal) } diff --git a/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala b/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala index ace82a9bbc80..b635c40b38b9 100644 --- a/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala +++ b/compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala @@ -1962,7 +1962,7 @@ class JSCodeGen()(implicit ctx: Context) { if (isStat) { boxedResult } else { - val tpe = ctx.atPhase(ctx.elimErasedValueTypePhase) { implicit ctx => + val tpe = ctx.atPhase(ctx.elimErasedValueTypePhase) { sym.info.finalResultType } unbox(boxedResult, tpe) @@ -2578,13 +2578,13 @@ class JSCodeGen()(implicit ctx: Context) { def paramNamesAndTypes(implicit ctx: Context): List[(Names.TermName, Type)] = sym.info.paramNamess.flatten.zip(sym.info.paramInfoss.flatten) - val wereRepeated = ctx.atPhase(ctx.elimRepeatedPhase) { implicit ctx => + val wereRepeated = ctx.atPhase(ctx.elimRepeatedPhase) { val list = for ((name, tpe) <- paramNamesAndTypes) yield (name -> tpe.isRepeatedParam) list.toMap } - val paramTypes = ctx.atPhase(ctx.elimErasedValueTypePhase) { implicit ctx => + val paramTypes = ctx.atPhase(ctx.elimErasedValueTypePhase) { paramNamesAndTypes.toMap } diff --git a/compiler/src/dotty/tools/backend/sjs/JSInterop.scala b/compiler/src/dotty/tools/backend/sjs/JSInterop.scala index e984489cf51d..664543ca599a 100644 --- a/compiler/src/dotty/tools/backend/sjs/JSInterop.scala +++ b/compiler/src/dotty/tools/backend/sjs/JSInterop.scala @@ -16,7 +16,7 @@ object JSInterop { /** Is this symbol a JavaScript type? */ def isJSType(sym: Symbol)(implicit ctx: Context): Boolean = { //sym.hasAnnotation(jsdefn.RawJSTypeAnnot) - ctx.atPhase(ctx.erasurePhase) { implicit ctx => + ctx.atPhase(ctx.erasurePhase) { sym.derivesFrom(jsdefn.JSAnyClass) } } @@ -32,7 +32,7 @@ object JSInterop { * much as *accessor* methods created for `val`s and `var`s. */ def isJSGetter(sym: Symbol)(implicit ctx: Context): Boolean = { - sym.info.firstParamTypes.isEmpty && ctx.atPhase(ctx.erasurePhase) { implicit ctx => + sym.info.firstParamTypes.isEmpty && ctx.atPhase(ctx.erasurePhase) { sym.info.isParameterless } } diff --git a/compiler/src/dotty/tools/dotc/core/Annotations.scala b/compiler/src/dotty/tools/dotc/core/Annotations.scala index 00204c9ba971..28cf9eda408c 100644 --- a/compiler/src/dotty/tools/dotc/core/Annotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Annotations.scala @@ -124,32 +124,32 @@ object Annotations { } /** Create an annotation where the tree is computed lazily. */ - def deferred(sym: Symbol, treeFn: Context => Tree)(implicit ctx: Context): Annotation = + def deferred(sym: Symbol)(treeFn: given Context => Tree)(implicit ctx: Context): Annotation = new LazyAnnotation { override def symbol(implicit ctx: Context): Symbol = sym - def complete(implicit ctx: Context) = treeFn(ctx) + def complete(implicit ctx: Context) = treeFn given ctx } /** Create an annotation where the symbol and the tree are computed lazily. */ - def deferredSymAndTree(symf: Context => Symbol, treeFn: Context => Tree)(implicit ctx: Context): Annotation = + def deferredSymAndTree(symf: given Context => Symbol)(treeFn: given Context => Tree)(implicit ctx: Context): Annotation = new LazyAnnotation { private[this] var mySym: Symbol = _ override def symbol(implicit ctx: Context): Symbol = { if (mySym == null || mySym.defRunId != ctx.runId) { - mySym = symf(ctx) + mySym = symf given ctx assert(mySym != null) } mySym } - def complete(implicit ctx: Context) = treeFn(ctx) + def complete(implicit ctx: Context) = treeFn given ctx } def deferred(atp: Type, args: List[Tree])(implicit ctx: Context): Annotation = - deferred(atp.classSymbol, implicit ctx => New(atp, args)) + deferred(atp.classSymbol)(New(atp, args)) def deferredResolve(atp: Type, args: List[Tree])(implicit ctx: Context): Annotation = - deferred(atp.classSymbol, implicit ctx => resolveConstructor(atp, args)) + deferred(atp.classSymbol)(resolveConstructor(atp, args)) def makeAlias(sym: TermSymbol)(implicit ctx: Context): Annotation = apply(defn.AliasAnnot, List( @@ -165,7 +165,7 @@ object Annotations { New(defn.ChildAnnotType.appliedTo(sym.owner.thisType.select(sym.name, sym)), Nil) .withSpan(span) } - deferred(defn.ChildAnnot, implicit ctx => makeChildLater(ctx)) + deferred(defn.ChildAnnot)(makeChildLater(ctx)) } /** A regular, non-deferred Child annotation */ diff --git a/compiler/src/dotty/tools/dotc/core/Contexts.scala b/compiler/src/dotty/tools/dotc/core/Contexts.scala index d261b025942b..36ad47b9e467 100644 --- a/compiler/src/dotty/tools/dotc/core/Contexts.scala +++ b/compiler/src/dotty/tools/dotc/core/Contexts.scala @@ -315,7 +315,7 @@ object Contexts { /** Run `op` as if it was run in a fresh explore typer state, but possibly * optimized to re-use the current typer state. */ - final def test[T](op: Context => T): T = typerState.test(op)(this) + final def test[T](op: given Context => T): T = typerState.test(op)(this) /** Is this a context for the members of a class definition? */ def isClassDefContext: Boolean = @@ -404,7 +404,7 @@ object Contexts { case _ => None } ctx.fresh.setImportInfo( - new ImportInfo(implicit ctx => sym, imp.selectors, impNameOpt, imp.importDelegate)) + ImportInfo(sym, imp.selectors, impNameOpt, imp.importDelegate)) } /** Does current phase use an erased types interpretation? */ diff --git a/compiler/src/dotty/tools/dotc/core/Decorators.scala b/compiler/src/dotty/tools/dotc/core/Decorators.scala index 0ca6b7f86c98..f562311d92c5 100644 --- a/compiler/src/dotty/tools/dotc/core/Decorators.scala +++ b/compiler/src/dotty/tools/dotc/core/Decorators.scala @@ -204,7 +204,7 @@ object Decorators { * give more info about type variables and to disambiguate where needed. */ def ex(args: Any*)(implicit ctx: Context): String = - explained(implicit ctx => em(args: _*)) + explained(em(args: _*)) } implicit class ArrayInterpolator[T <: AnyRef](val arr: Array[T]) extends AnyVal { diff --git a/compiler/src/dotty/tools/dotc/core/Periods.scala b/compiler/src/dotty/tools/dotc/core/Periods.scala index f1bfa4d0c7f6..73298d80287f 100644 --- a/compiler/src/dotty/tools/dotc/core/Periods.scala +++ b/compiler/src/dotty/tools/dotc/core/Periods.scala @@ -21,8 +21,8 @@ abstract class Periods { self: Context => op(ctx.fresh.setPeriod(pd)) /** Execute `op` at given phase id */ - def atPhase[T](pid: PhaseId)(op: Context => T): T = - op(ctx.withPhase(pid)) + def atPhase[T](pid: PhaseId)(op: given Context => T): T = + op given ctx.withPhase(pid) /** The period containing the current period where denotations do not change. * We compute this by taking as first phase the first phase less or equal to diff --git a/compiler/src/dotty/tools/dotc/core/Phases.scala b/compiler/src/dotty/tools/dotc/core/Phases.scala index f0ca3d3a7a6d..5341fec243ec 100644 --- a/compiler/src/dotty/tools/dotc/core/Phases.scala +++ b/compiler/src/dotty/tools/dotc/core/Phases.scala @@ -31,13 +31,13 @@ trait Phases { } /** Execute `op` at given phase */ - def atPhase[T](phase: Phase)(op: Context => T): T = + def atPhase[T](phase: Phase)(op: given Context => T): T = atPhase(phase.id)(op) - def atNextPhase[T](op: Context => T): T = atPhase(phase.next)(op) + def atNextPhase[T](op: given Context => T): T = atPhase(phase.next)(op) - def atPhaseNotLaterThan[T](limit: Phase)(op: Context => T): T = - if (!limit.exists || phase <= limit) op(this) else atPhase(limit)(op) + def atPhaseNotLaterThan[T](limit: Phase)(op: given Context => T): T = + if (!limit.exists || phase <= limit) op given this else atPhase(limit)(op) def isAfterTyper: Boolean = base.isAfterTyper(phase) } diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index 7c194b3a7283..d5eb260caf02 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -195,7 +195,7 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w //} assert(!ctx.settings.YnoDeepSubtypes.value) if (Config.traceDeepSubTypeRecursions && !this.isInstanceOf[ExplainingTypeComparer]) - ctx.log(TypeComparer.explained(implicit ctx => ctx.typeComparer.isSubType(tp1, tp2, approx))) + ctx.log(TypeComparer.explained(the[Context].typeComparer.isSubType(tp1, tp2, approx))) } // Eliminate LazyRefs before checking whether we have seen a type before val normalize = new TypeMap { @@ -2307,15 +2307,15 @@ object TypeComparer { */ val FreshApprox: ApproxState = new ApproxState(4) - /** Show trace of comparison operations when performing `op` as result string */ - def explaining[T](say: String => Unit)(op: Context => T)(implicit ctx: Context): T = { + /** Show trace of comparison operations when performing `op` */ + def explaining[T](say: String => Unit)(op: given Context => T)(implicit ctx: Context): T = { val nestedCtx = ctx.fresh.setTypeComparerFn(new ExplainingTypeComparer(_)) - val res = try { op(nestedCtx) } finally { say(nestedCtx.typeComparer.lastTrace()) } + val res = try { op given nestedCtx } finally { say(nestedCtx.typeComparer.lastTrace()) } res } /** Like [[explaining]], but returns the trace instead */ - def explained[T](op: Context => T)(implicit ctx: Context): String = { + def explained[T](op: given Context => T)(implicit ctx: Context): String = { var trace: String = null try { explaining(trace = _)(op) } catch { case ex: Throwable => ex.printStackTrace } trace diff --git a/compiler/src/dotty/tools/dotc/core/TyperState.scala b/compiler/src/dotty/tools/dotc/core/TyperState.scala index 5274a2beef9d..bb2ec044fc80 100644 --- a/compiler/src/dotty/tools/dotc/core/TyperState.scala +++ b/compiler/src/dotty/tools/dotc/core/TyperState.scala @@ -96,9 +96,9 @@ class TyperState(private val previous: TyperState /* | Null */) { * typerstate. If it is unshared, run `op` in current typerState, restoring typerState * to previous state afterwards. */ - def test[T](op: Context => T)(implicit ctx: Context): T = + def test[T](op: given Context => T)(implicit ctx: Context): T = if (isShared) - op(ctx.fresh.setExploreTyperState()) + op given ctx.fresh.setExploreTyperState() else { val savedConstraint = myConstraint val savedReporter = myReporter @@ -114,7 +114,7 @@ class TyperState(private val previous: TyperState /* | Null */) { testReporter.inUse = true testReporter } - try op(ctx) + try op given ctx finally { testReporter.inUse = false resetConstraintTo(savedConstraint) diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index 51cff426e959..06148af83101 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -658,9 +658,7 @@ class TreeUnpickler(reader: TastyReader, val lazyAnnotTree = readLaterWithOwner(end, rdr => ctx => rdr.readTerm()(ctx)) owner => - Annotation.deferredSymAndTree( - implicit ctx => tp.typeSymbol, - implicit ctx => lazyAnnotTree(owner).complete) + Annotation.deferredSymAndTree(tp.typeSymbol)(lazyAnnotTree(owner).complete) } /** Create symbols for the definitions in the statement sequence between diff --git a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index b6718327a3df..01b51ae7d315 100644 --- a/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -972,9 +972,8 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas val start = readIndex val atp = readTypeRef() val phase = ctx.phase - Annotation.deferred( - atp.typeSymbol, implicit ctx => - atReadPos(start, () => readAnnotationContents(end)(ctx.withPhase(phase)))) + Annotation.deferred(atp.typeSymbol)( + atReadPos(start, () => readAnnotationContents(end)(the[Context].withPhase(phase)))) } /* Read an abstract syntax tree */ diff --git a/compiler/src/dotty/tools/dotc/interactive/Interactive.scala b/compiler/src/dotty/tools/dotc/interactive/Interactive.scala index 24817953b93f..46e482f693bc 100644 --- a/compiler/src/dotty/tools/dotc/interactive/Interactive.scala +++ b/compiler/src/dotty/tools/dotc/interactive/Interactive.scala @@ -379,16 +379,16 @@ object Interactive { */ def localize(symbol: Symbol, sourceDriver: InteractiveDriver, targetDriver: InteractiveDriver): Symbol = { - def in[T](driver: InteractiveDriver)(fn: Context => T): T = - fn(driver.currentCtx) + def in[T](driver: InteractiveDriver)(fn: given Context => T): T = + fn given driver.currentCtx if (sourceDriver == targetDriver) symbol else { - val owners = in(sourceDriver) { implicit ctx => + val owners = in(sourceDriver) { symbol.ownersIterator.toList.reverse.map(_.name) } - in(targetDriver) { implicit ctx => - val base: Symbol = ctx.definitions.RootClass + in(targetDriver) { + val base: Symbol = defn.RootClass owners.tail.foldLeft(base) { (prefix, symbolName) => if (prefix.exists) prefix.info.member(symbolName).symbol else NoSymbol diff --git a/compiler/src/dotty/tools/dotc/printing/Formatting.scala b/compiler/src/dotty/tools/dotc/printing/Formatting.scala index 49a8c7cf3aa7..9be652e4eea3 100644 --- a/compiler/src/dotty/tools/dotc/printing/Formatting.scala +++ b/compiler/src/dotty/tools/dotc/printing/Formatting.scala @@ -252,9 +252,9 @@ object Formatting { * ex"disambiguate $tpe1 and $tpe2" * ``` */ - def explained(op: Context => String)(implicit ctx: Context): String = { + def explained(op: given Context => String)(implicit ctx: Context): String = { val seen = new Seen - val msg = op(explainCtx(seen)) + val msg = op given explainCtx(seen) val addendum = explanations(seen) if (addendum.isEmpty) msg else msg ++ "\n\n" ++ addendum } diff --git a/compiler/src/dotty/tools/dotc/transform/CheckReentrant.scala b/compiler/src/dotty/tools/dotc/transform/CheckReentrant.scala index 98a3cb12d54e..9b950869f7d5 100644 --- a/compiler/src/dotty/tools/dotc/transform/CheckReentrant.scala +++ b/compiler/src/dotty/tools/dotc/transform/CheckReentrant.scala @@ -36,9 +36,9 @@ class CheckReentrant extends MiniPhase { private[this] var seen: Set[ClassSymbol] = Set() private[this] var indent: Int = 0 - private val sharableAnnot = new CtxLazy(implicit ctx => + private val sharableAnnot = new CtxLazy(given ctx => ctx.requiredClass("scala.annotation.internal.sharable")) - private val unsharedAnnot = new CtxLazy(implicit ctx => + private val unsharedAnnot = new CtxLazy(given ctx => ctx.requiredClass("scala.annotation.internal.unshared")) def isIgnored(sym: Symbol)(implicit ctx: Context): Boolean = diff --git a/compiler/src/dotty/tools/dotc/transform/CtxLazy.scala b/compiler/src/dotty/tools/dotc/transform/CtxLazy.scala index a22d24ebbb17..d855f409eda0 100644 --- a/compiler/src/dotty/tools/dotc/transform/CtxLazy.scala +++ b/compiler/src/dotty/tools/dotc/transform/CtxLazy.scala @@ -11,12 +11,12 @@ import core.Contexts.Context * A typical use case is a lazy val in a phase object which exists once per root context where * the expression intiializing the lazy val depends only on the root context, but not any changes afterwards. */ -class CtxLazy[T](expr: Context => T) { +class CtxLazy[T](expr: given Context => T) { private[this] var myValue: T = _ private[this] var forced = false def apply()(implicit ctx: Context): T = { if (!forced) { - myValue = expr(ctx) + myValue = expr given ctx forced = true } myValue diff --git a/compiler/src/dotty/tools/dotc/transform/ElimByName.scala b/compiler/src/dotty/tools/dotc/transform/ElimByName.scala index e5474439f8dd..a3afecdf35a4 100644 --- a/compiler/src/dotty/tools/dotc/transform/ElimByName.scala +++ b/compiler/src/dotty/tools/dotc/transform/ElimByName.scala @@ -42,7 +42,7 @@ class ElimByName extends TransformByNameApply with InfoTransformer { private def applyIfFunction(tree: Tree, ftree: Tree)(implicit ctx: Context) = if (isByNameRef(ftree)) { val tree0 = transformFollowing(tree) - ctx.atPhase(next) { implicit ctx => tree0.select(defn.Function0_apply).appliedToNone } + ctx.atPhase(next) { tree0.select(defn.Function0_apply).appliedToNone } } else tree @@ -61,7 +61,7 @@ class ElimByName extends TransformByNameApply with InfoTransformer { } override def transformValDef(tree: ValDef)(implicit ctx: Context): Tree = - ctx.atPhase(next) { implicit ctx => + ctx.atPhase(next) { if (exprBecomesFunction(tree.symbol)) cpy.ValDef(tree)(tpt = tree.tpt.withType(tree.symbol.info)) else tree diff --git a/compiler/src/dotty/tools/dotc/transform/ElimRepeated.scala b/compiler/src/dotty/tools/dotc/transform/ElimRepeated.scala index a7f067e561ef..9c60d8848b2e 100644 --- a/compiler/src/dotty/tools/dotc/transform/ElimRepeated.scala +++ b/compiler/src/dotty/tools/dotc/transform/ElimRepeated.scala @@ -112,7 +112,7 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase => * Also transform trees inside method annotation */ override def transformDefDef(tree: DefDef)(implicit ctx: Context): Tree = - ctx.atPhase(thisPhase) { implicit ctx => + ctx.atPhase(thisPhase) { if (tree.symbol.info.isVarArgsMethod && overridesJava(tree.symbol)) addVarArgsBridge(tree) else diff --git a/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala b/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala index c9e64ec89797..1b57ccec8d50 100644 --- a/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala +++ b/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala @@ -131,7 +131,7 @@ object ExplicitOuter { /** Ensure that class `cls` has outer accessors */ def ensureOuterAccessors(cls: ClassSymbol)(implicit ctx: Context): Unit = - ctx.atPhase(ctx.explicitOuterPhase.next) { implicit ctx => + ctx.atPhase(ctx.explicitOuterPhase.next) { if (!hasOuter(cls)) newOuterAccessors(cls).foreach(_.enteredAfter(ctx.explicitOuterPhase.asInstanceOf[DenotTransformer])) } diff --git a/compiler/src/dotty/tools/dotc/transform/ExtensionMethods.scala b/compiler/src/dotty/tools/dotc/transform/ExtensionMethods.scala index 490479c8d953..a45b2e32ce6b 100644 --- a/compiler/src/dotty/tools/dotc/transform/ExtensionMethods.scala +++ b/compiler/src/dotty/tools/dotc/transform/ExtensionMethods.scala @@ -217,7 +217,7 @@ object ExtensionMethods { /** Return the extension method that corresponds to given instance method `meth`. */ def extensionMethod(imeth: Symbol)(implicit ctx: Context): TermSymbol = - ctx.atPhase(ctx.extensionMethodsPhase.next) { implicit ctx => + ctx.atPhase(ctx.extensionMethodsPhase.next) { // FIXME use toStatic instead? val companion = imeth.owner.companionModule val companionInfo = companion.info diff --git a/compiler/src/dotty/tools/dotc/transform/FunctionalInterfaces.scala b/compiler/src/dotty/tools/dotc/transform/FunctionalInterfaces.scala index a685219ad69c..f8d530a8a904 100644 --- a/compiler/src/dotty/tools/dotc/transform/FunctionalInterfaces.scala +++ b/compiler/src/dotty/tools/dotc/transform/FunctionalInterfaces.scala @@ -35,9 +35,7 @@ class FunctionalInterfaces extends MiniPhase { if (defn.isSpecializableFunction(cls, implParamTypes, implResultType) && !ctx.settings.scalajs.value) { // never do anything for Scala.js, but do this test as late as possible not to slow down Scala/JVM - val names = ctx.atPhase(ctx.erasurePhase) { - implicit ctx => cls.typeParams.map(_.name) - } + val names = ctx.atPhase(ctx.erasurePhase) { cls.typeParams.map(_.name) } val interfaceName = (functionName ++ implParamTypes.length.toString).specializedFor(implParamTypes ::: implResultType :: Nil, names, Nil, Nil) // symbols loaded from classpath aren't defined in periods earlier than when they where loaded diff --git a/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala b/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala index b465452f4bdf..297014362ac7 100644 --- a/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala +++ b/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala @@ -119,7 +119,7 @@ object GenericSignatures { // a type parameter or similar) must go through here or the signature is // likely to end up with Foo.Empty where it needs Foo.Empty$. def fullNameInSig(sym: Symbol): Unit = { - val name = ctx.atPhase(ctx.genBCodePhase) { implicit ctx => sanitizeName(sym.fullName).replace('.', '/') } + val name = ctx.atPhase(ctx.genBCodePhase) { sanitizeName(sym.fullName).replace('.', '/') } builder.append('L').append(name) } diff --git a/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala b/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala index 679da56495be..4bd73238797b 100644 --- a/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala +++ b/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala @@ -358,7 +358,7 @@ object LambdaLift { } // initialization - ctx.atPhase(thisPhase) { implicit ctx => + ctx.atPhase(thisPhase) { (new CollectDependencies).traverse(ctx.compilationUnit.tpdTree) computeFreeVars() computeLiftedOwners() diff --git a/compiler/src/dotty/tools/dotc/transform/Mixin.scala b/compiler/src/dotty/tools/dotc/transform/Mixin.scala index f4d05919f31e..af40223d1421 100644 --- a/compiler/src/dotty/tools/dotc/transform/Mixin.scala +++ b/compiler/src/dotty/tools/dotc/transform/Mixin.scala @@ -207,7 +207,7 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase => } def wasOneOf(sym: Symbol, flags: FlagSet) = - ctx.atPhase(thisPhase) { implicit ctx => sym.isOneOf(flags) } + ctx.atPhase(thisPhase) { sym.isOneOf(flags) } def traitInits(mixin: ClassSymbol): List[Tree] = { var argNum = 0 diff --git a/compiler/src/dotty/tools/dotc/transform/MixinOps.scala b/compiler/src/dotty/tools/dotc/transform/MixinOps.scala index 9461da6e9417..06541170e6fa 100644 --- a/compiler/src/dotty/tools/dotc/transform/MixinOps.scala +++ b/compiler/src/dotty/tools/dotc/transform/MixinOps.scala @@ -43,7 +43,7 @@ class MixinOps(cls: ClassSymbol, thisPhase: DenotTransformer)(implicit ctx: Cont * The test is performed at phase `thisPhase`. */ def isCurrent(sym: Symbol): Boolean = - ctx.atPhase(thisPhase) { implicit ctx => + ctx.atPhase(thisPhase) { cls.info.nonPrivateMember(sym.name).hasAltWith(_.symbol == sym) } diff --git a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala index 7dc697c44d6f..09d592bcfbc5 100644 --- a/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala +++ b/compiler/src/dotty/tools/dotc/transform/TreeChecker.scala @@ -57,7 +57,7 @@ class TreeChecker extends Phase with SymTransformer { def checkCompanion(symd: SymDenotation)(implicit ctx: Context): Unit = { val cur = symd.linkedClass - val prev = ctx.atPhase(ctx.phase.prev) { implicit ctx => + val prev = ctx.atPhase(ctx.phase.prev) { symd.symbol.linkedClass } diff --git a/compiler/src/dotty/tools/dotc/transform/ValueClasses.scala b/compiler/src/dotty/tools/dotc/transform/ValueClasses.scala index 311eb184824f..c2f81b8dcde3 100644 --- a/compiler/src/dotty/tools/dotc/transform/ValueClasses.scala +++ b/compiler/src/dotty/tools/dotc/transform/ValueClasses.scala @@ -22,9 +22,9 @@ object ValueClasses { } def isMethodWithExtension(sym: Symbol)(implicit ctx: Context): Boolean = - ctx.atPhaseNotLaterThan(ctx.extensionMethodsPhase) { implicit ctx => + ctx.atPhaseNotLaterThan(ctx.extensionMethodsPhase) { val d = sym.denot - d.validFor.containsPhaseId(ctx.phaseId) && + d.validFor.containsPhaseId(the[Context].phaseId) && d.isRealMethod && isDerivedValueClass(d.owner) && !d.isConstructor && diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index 09fe654107a2..f77ac686a71a 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -410,7 +410,7 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic { /** Is `tp1` a subtype of `tp2`? */ def isSubType(tp1: Type, tp2: Type): Boolean = { - debug.println(TypeComparer.explained(implicit ctx => tp1 <:< tp2)) + debug.println(TypeComparer.explained(tp1 <:< tp2)) val res = (tp1 != nullType || tp2 == nullType) && tp1 <:< tp2 res } diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala index 05eb24d34622..c81bda680bbf 100644 --- a/compiler/src/dotty/tools/dotc/typer/Applications.scala +++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala @@ -788,7 +788,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic => * Fallback if this fails: try to convert `E` to `new E`. */ def typedFunPart(fn: untpd.Tree, pt: Type)(implicit ctx: Context): Tree = - tryEither { implicit ctx => + tryEither { typedExpr(fn, pt) } { (result, tstate) => def fallBack = { @@ -852,7 +852,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic => else tryInsertImplicitOnQualifier(fun1, proto, ctx.typerState.ownedVars) flatMap { fun2 => tryEither { - implicit ctx => Some(simpleApply(fun2, proto)): Option[Tree] + Some(simpleApply(fun2, proto)): Option[Tree] } { (_, _) => None } @@ -865,7 +865,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic => if (originalProto.isDropped) fun1 else tryEither { - implicit ctx => simpleApply(fun1, proto) + simpleApply(fun1, proto) } { (failedVal, failedState) => def fail = { failedState.commit(); failedVal } @@ -901,10 +901,10 @@ trait Applications extends Compatibility { self: Typer with Dynamic => val app1 = if (untpd.isOpAssign(tree)) tryEither { - implicit ctx => realApply + realApply } { (failedVal, failedState) => tryEither { - implicit ctx => typedOpAssign + typedOpAssign } { (_, _) => failedState.commit() failedVal @@ -1045,11 +1045,11 @@ trait Applications extends Compatibility { self: Typer with Dynamic => // Reject in this case. } tryEither { - implicit ctx => tryWithProto(selType) + tryWithProto(selType) } { (sel, _) => tryEither { - implicit ctx => tryWithProto(WildcardType) + tryWithProto(WildcardType) } { (_, _) => fallBack(sel) } @@ -1153,20 +1153,20 @@ trait Applications extends Compatibility { self: Typer with Dynamic => def isApplicableMethodRef(methRef: TermRef, targs: List[Type], args: List[Tree], resultType: Type, keepConstraint: Boolean)(implicit ctx: Context): Boolean = { def isApp(implicit ctx: Context): Boolean = new ApplicableToTrees(methRef, targs, args, resultType).success - if (keepConstraint) isApp else ctx.test(implicit ctx => isApp) + if (keepConstraint) isApp else ctx.test(isApp) } /** Is given method reference applicable to type arguments `targs` and argument trees `args` without inferring views? * @param resultType The expected result type of the application */ def isDirectlyApplicableMethodRef(methRef: TermRef, targs: List[Type], args: List[Tree], resultType: Type)(implicit ctx: Context): Boolean = - ctx.test(implicit ctx => new ApplicableToTreesDirectly(methRef, targs, args, resultType).success) + ctx.test(new ApplicableToTreesDirectly(methRef, targs, args, resultType).success) /** Is given method reference applicable to argument types `args`? * @param resultType The expected result type of the application */ def isApplicableMethodRef(methRef: TermRef, args: List[Type], resultType: Type)(implicit ctx: Context): Boolean = - ctx.test(implicit ctx => new ApplicableToTypes(methRef, args, resultType).success) + ctx.test(new ApplicableToTypes(methRef, args, resultType).success) /** Is given type applicable to type arguments `targs` and argument trees `args`, * possibly after inserting an `apply`? @@ -1287,7 +1287,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic => case tp2: MethodType => true // (3a) case tp2: PolyType if tp2.resultType.isInstanceOf[MethodType] => true // (3a) case tp2: PolyType => // (3b) - ctx.test(implicit ctx => isAsSpecificValueType(tp1, constrained(tp2).resultType)) + ctx.test(isAsSpecificValueType(tp1, constrained(tp2).resultType)) case _ => // (3b) isAsSpecificValueType(tp1, tp2) } @@ -1481,9 +1481,9 @@ trait Applications extends Compatibility { self: Typer with Dynamic => * do they prune much, on average. */ def adaptByResult(chosen: TermRef, alts: List[TermRef]) = pt match { - case pt: FunProto if !ctx.test(implicit ctx => resultConforms(chosen.symbol, chosen, pt.resultType)) => + case pt: FunProto if !ctx.test(resultConforms(chosen.symbol, chosen, pt.resultType)) => val conformingAlts = alts.filter(alt => - (alt ne chosen) && ctx.test(implicit ctx => resultConforms(alt.symbol, alt, pt.resultType))) + (alt ne chosen) && ctx.test(resultConforms(alt.symbol, alt, pt.resultType))) conformingAlts match { case Nil => chosen case alt2 :: Nil => alt2 diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index bf4d43c7d04a..09be52698584 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -102,7 +102,7 @@ object Implicits { else if (mt.paramInfos.lengthCompare(1) == 0 && { var formal = widenSingleton(mt.paramInfos.head) if (approx) formal = wildApprox(formal) - ctx.test(implicit ctx => argType relaxed_<:< formal.widenExpr) + ctx.test(argType relaxed_<:< formal.widenExpr) }) Candidate.Conversion else @@ -216,7 +216,7 @@ object Implicits { val nestedCtx = ctx.fresh.addMode(Mode.TypevarsMissContext) def matchingCandidate(ref: ImplicitRef): Option[Candidate] = - nestedCtx.test(implicit ctx => candidateKind(ref.underlyingRef)) match { + nestedCtx.test(candidateKind(ref.underlyingRef)) match { case Candidate.None => None case ckind => Some(new Candidate(ref, ckind, level)) } @@ -648,7 +648,7 @@ trait Implicits { self: Typer => case ex: AssertionError => implicits.println(s"view $from ==> $to") implicits.println(ctx.typerState.constraint.show) - implicits.println(TypeComparer.explained(implicit ctx => from.tpe <:< to)) + implicits.println(TypeComparer.explained(from.tpe <:< to)) throw ex } } @@ -808,7 +808,7 @@ trait Implicits { self: Typer => if (canComparePredefined(arg1, arg2) || !strictEquality && - ctx.test(implicit ctx => validEqAnyArgs(arg1, arg2))) + ctx.test(validEqAnyArgs(arg1, arg2))) ref(defn.Eql_eqlAny).appliedToTypes(args).withSpan(span) else EmptyTree case _ => @@ -1391,7 +1391,7 @@ trait Implicits { self: Typer => def compareCandidate(prev: SearchSuccess, ref: TermRef, level: Int): Int = if (prev.ref eq ref) 0 else if (prev.level != level) prev.level - level - else nestedContext().test(implicit ctx => compare(prev.ref, ref)) + else nestedContext().test(compare(prev.ref, ref)) /** If `alt1` is also a search success, try to disambiguate as follows: * - If alt2 is preferred over alt1, pick alt2, otherwise return an diff --git a/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala b/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala index 313adfbf5ccb..84f091f26414 100644 --- a/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala +++ b/compiler/src/dotty/tools/dotc/typer/ImportInfo.scala @@ -19,7 +19,7 @@ object ImportInfo { val selectors = untpd.Ident(nme.WILDCARD) :: Nil def expr(implicit ctx: Context) = tpd.Ident(refFn()) def imp(implicit ctx: Context) = tpd.Import(importDelegate = importDelegate, expr, selectors) - new ImportInfo(implicit ctx => imp.symbol, selectors, None, importDelegate = importDelegate, isRootImport = true) + new ImportInfo(imp.symbol, selectors, None, importDelegate = importDelegate, isRootImport = true) } } @@ -32,7 +32,7 @@ object ImportInfo { * @param isRootImport true if this is one of the implicit imports of scala, java.lang, * scala.Predef or dotty.DottyPredef in the start context, false otherwise. */ -class ImportInfo(symf: Context => Symbol, val selectors: List[untpd.Tree], +class ImportInfo(symf: given Context => Symbol, val selectors: List[untpd.Tree], symNameOpt: Option[TermName], val importDelegate: Boolean, val isRootImport: Boolean = false) extends Showable { @@ -41,7 +41,7 @@ class ImportInfo(symf: Context => Symbol, val selectors: List[untpd.Tree], // that we cannot use one for `DottyPredefModuleRef`. def sym(implicit ctx: Context): Symbol = { if (mySym == null) { - mySym = symf(ctx) + mySym = symf given ctx assert(mySym != null) } mySym diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 61e7c016a617..7e1367d12573 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -795,7 +795,7 @@ class Namer { typer: Typer => if (cls eq sym) ctx.error("An annotation class cannot be annotated with iself", annotTree.sourcePos) else { - val ann = Annotation.deferred(cls, implicit ctx => typedAnnotation(annotTree)) + val ann = Annotation.deferred(cls)(typedAnnotation(annotTree)) sym.addAnnotation(ann) if (cls == defn.ForceInlineAnnot && sym.is(Method, butNot = Accessor)) sym.setFlag(Inline) diff --git a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala index 9eafce747966..9f83157981b5 100644 --- a/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -56,7 +56,7 @@ object ProtoTypes { normalizedCompatible(tp, pt, keepConstraint = false) case _ => testCompat } - else ctx.test(implicit ctx => testCompat) + else ctx.test(testCompat) } private def disregardProto(pt: Type)(implicit ctx: Context): Boolean = pt.dealias match { diff --git a/compiler/src/dotty/tools/dotc/typer/RefChecks.scala b/compiler/src/dotty/tools/dotc/typer/RefChecks.scala index eb06127580eb..5c51d259919e 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 hasJavaErasedOverriding(sym: Symbol): Boolean = !ctx.erasurePhase.exists || // can't do the test, assume the best - ctx.atPhase(ctx.erasurePhase.next) { implicit ctx => + ctx.atPhase(ctx.erasurePhase.next) { clazz.info.nonPrivateMember(sym.name).hasAltWith { alt => alt.symbol.is(JavaDefined, butNot = Deferred) && !sym.owner.derivesFrom(alt.symbol.owner) && diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 6857bb901b55..b2ac7e80535e 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -49,7 +49,7 @@ object Typer { */ enum BindingPrec { case NothingBound, PackageClause, WildImport, NamedImport, Definition - + def isImportPrec = this == NamedImport || this == WildImport } @@ -472,8 +472,8 @@ class Typer extends Namer case _ => errorTree(tree, "cannot convert to type selection") // will never be printed due to fallback } - def selectWithFallback(fallBack: Context => Tree) = - tryAlternatively(typeSelectOnTerm(_))(fallBack) + def selectWithFallback(fallBack: given Context => Tree) = + tryAlternatively(typeSelectOnTerm)(fallBack) if (tree.qualifier.isType) { val qual1 = typedType(tree.qualifier, selectionProto(tree.name, pt, this)) @@ -482,7 +482,7 @@ class Typer extends Namer else if (ctx.compilationUnit.isJava && tree.name.isTypeName) // SI-3120 Java uses the same syntax, A.B, to express selection from the // value A and from the type A. We have to try both. - selectWithFallback(tryJavaSelectOnType(_)) // !!! possibly exponential bcs of qualifier retyping + selectWithFallback(tryJavaSelectOnType) // !!! possibly exponential bcs of qualifier retyping else typeSelectOnTerm(ctx) } @@ -2511,9 +2511,9 @@ class Typer extends Namer def typedPattern(tree: untpd.Tree, selType: Type = WildcardType)(implicit ctx: Context): Tree = typed(tree, selType)(ctx addMode Mode.Pattern) - def tryEither[T](op: Context => T)(fallBack: (T, TyperState) => T)(implicit ctx: Context): T = { + def tryEither[T](op: given Context => T)(fallBack: (T, TyperState) => T)(implicit ctx: Context): T = { val nestedCtx = ctx.fresh.setNewTyperState() - val result = op(nestedCtx) + val result = op given nestedCtx if (nestedCtx.reporter.hasErrors && !nestedCtx.reporter.hasStickyErrors) { record("tryEither.fallBack") fallBack(result, nestedCtx.typerState) @@ -2528,7 +2528,7 @@ class Typer extends Namer /** Try `op1`, if there are errors, try `op2`, if `op2` also causes errors, fall back * to errors and result of `op1`. */ - def tryAlternatively[T](op1: Context => T)(op2: Context => T)(implicit ctx: Context): T = + def tryAlternatively[T](op1: given Context => T)(op2: given Context => T)(implicit ctx: Context): T = tryEither(op1) { (failedVal, failedState) => tryEither(op2) { (_, _) => failedState.commit() @@ -2553,9 +2553,9 @@ class Typer extends Namer (treesInst: Instance[T])(tree: Trees.Tree[T], pt: Type, fallBack: => Tree)(implicit ctx: Context): Tree = { def tryWithType(tpt: untpd.Tree): Tree = - tryEither { implicit ctx => + tryEither { val tycon = typed(tpt) - if (ctx.reporter.hasErrors) + if (the[Context].reporter.hasErrors) EmptyTree // signal that we should return the error in fallBack else { def recur(tpt: Tree, pt: Type): Tree = pt.revealIgnored match { @@ -2648,7 +2648,7 @@ class Typer extends Namer tree case _ => if (isApplyProto(pt) || isMethod(tree) || isSyntheticApply(tree)) tryImplicit(fallBack) - else tryEither(tryApply(_)) { (app, appState) => + else tryEither(tryApply) { (app, appState) => tryImplicit { if (tree.tpe.member(nme.apply).exists) { // issue the error about the apply, since it is likely more informative than the fallback @@ -2668,9 +2668,9 @@ class Typer extends Namer tree match { case Select(qual, name) if name != nme.CONSTRUCTOR => val qualProto = SelectionProto(name, pt, NoViewsAllowed, privateOK = false) - tryEither { implicit ctx => + tryEither { val qual1 = adapt(qual, qualProto, locked) - if ((qual eq qual1) || ctx.reporter.hasErrors) None + if ((qual eq qual1) || the[Context].reporter.hasErrors) None else Some(typed(cpy.Select(tree)(untpd.TypedSplice(qual1), name), pt, locked)) } { (_, _) => None } @@ -2887,7 +2887,7 @@ class Typer extends Namer val namedArgs = (wtp.paramNames, args).zipped.flatMap { (pname, arg) => if (arg.tpe.isError) Nil else untpd.NamedArg(pname, untpd.TypedSplice(arg)) :: Nil } - tryEither { implicit ctx => + tryEither { val app = cpy.Apply(tree)(untpd.TypedSplice(tree), namedArgs) if (wtp.isContextualMethod) app.setGivenApply() typr.println(i"try with default implicit args $app") @@ -3037,7 +3037,7 @@ class Typer extends Namer case wtp: MethodType => missingArgs(wtp) case _ => typr.println(i"adapt to subtype ${tree.tpe} !<:< $pt") - //typr.println(TypeComparer.explained(implicit ctx => tree.tpe <:< pt)) + //typr.println(TypeComparer.explained(tree.tpe <:< pt)) adaptToSubType(wtp) } } diff --git a/compiler/src/dotty/tools/repl/ReplDriver.scala b/compiler/src/dotty/tools/repl/ReplDriver.scala index 136f8652df56..9ccf543e4c93 100644 --- a/compiler/src/dotty/tools/repl/ReplDriver.scala +++ b/compiler/src/dotty/tools/repl/ReplDriver.scala @@ -291,8 +291,7 @@ class ReplDriver(settings: Array[String], } - ctx.atPhase(ctx.typerPhase.next) { implicit ctx => - + ctx.atPhase(ctx.typerPhase.next) { // Display members of wrapped module: tree.symbol.info.memberClasses .find(_.symbol.name == newestWrapper.moduleClassName) diff --git a/tests/pos-with-compiler/DecoratorsX.scala b/tests/pos-with-compiler/DecoratorsX.scala deleted file mode 100644 index c516aa9b290f..000000000000 --- a/tests/pos-with-compiler/DecoratorsX.scala +++ /dev/null @@ -1,205 +0,0 @@ -package dotty.tools.dotc -package core - -import annotation.tailrec -import Symbols._ -import Contexts._, Names._, Phases._, printing.Texts._, printing.Printer -import util.Spans.Span, util.SourcePosition -import collection.mutable.ListBuffer -import dotty.tools.dotc.transform.MegaPhase -import ast.tpd._ -import scala.language.implicitConversions -import printing.Formatting._ - -/** This object provides useful conversions and extension methods for types defined elsewhere */ -object DecoratorsX { - - /** Turns Strings into PreNames, adding toType/TermName methods */ - class StringPreName(s: String) extends AnyVal with PreName { - def toTypeName: TypeName = typeName(s) - def toTermName: TermName = termName(s) - def toText(printer: Printer): Text = Str(s) - } - delegate for Conversion[String, StringPreName] = new StringPreName(_) - - final val MaxFilterRecursions = 1000 - - delegate { - def (s: String) splitWhere (f: Char => Boolean, doDropIndex: Boolean): Option[(String, String)] = { - def splitAt(idx: Int, doDropIndex: Boolean): Option[(String, String)] = - if (idx == -1) None - else Some((s.take(idx), s.drop(if (doDropIndex) idx + 1 else idx))) - - splitAt(s.indexWhere(f), doDropIndex) - } - - /** Implements a findSymbol method on iterators of Symbols that - * works like find but avoids Option, replacing None with NoSymbol. - */ - def (it: Iterator[Symbol]) findSymbol(p: Symbol => Boolean): Symbol = { - while (it.hasNext) { - val sym = it.next() - if (p(sym)) return sym - } - NoSymbol - } - - def (xs: List[T]) mapconserve [T, U] (f: T => U): List[U] = { - @tailrec - def loop(mapped: ListBuffer[U], unchanged: List[U], pending: List[T]): List[U] = - if (pending.isEmpty) { - if (mapped eq null) unchanged - else mapped.prependToList(unchanged) - } else { - val head0 = pending.head - val head1 = f(head0) - - if (head1.asInstanceOf[AnyRef] eq head0.asInstanceOf[AnyRef]) - loop(mapped, unchanged, pending.tail) - else { - val b = if (mapped eq null) new ListBuffer[U] else mapped - var xc = unchanged - while (xc ne pending) { - b += xc.head - xc = xc.tail - } - b += head1 - val tail0 = pending.tail - loop(b, tail0.asInstanceOf[List[U]], tail0) - } - } - loop(null, xs.asInstanceOf[List[U]], xs) - } - - /** Like `xs filter p` but returns list `xs` itself - instead of a copy - - * if `p` is true for all elements and `xs` is not longer - * than `MaxFilterRecursions`. - */ - def (xs: List[T]) filterConserve [T] (p: T => Boolean): List[T] = { - def loop(xs: List[T], nrec: Int): List[T] = xs match { - case Nil => xs - case x :: xs1 => - if (nrec < MaxFilterRecursions) { - val ys1 = loop(xs1, nrec + 1) - if (p(x)) - if (ys1 eq xs1) xs else x :: ys1 - else - ys1 - } else xs filter p - } - loop(xs, 0) - } - - /** Like `(xs, ys).zipped.map(f)`, but returns list `xs` itself - * - instead of a copy - if function `f` maps all elements of - * `xs` to themselves. Also, it is required that `ys` is at least - * as long as `xs`. - */ - def (xs: List[T]) zipWithConserve [T, U] (ys: List[U])(f: (T, U) => T): List[T] = - if (xs.isEmpty || ys.isEmpty) Nil - else { - val x1 = f(xs.head, ys.head) - val xs1 = xs.tail.zipWithConserve(ys.tail)(f) - if ((x1.asInstanceOf[AnyRef] eq xs.head.asInstanceOf[AnyRef]) && - (xs1 eq xs.tail)) xs - else x1 :: xs1 - } - - def (xs: List[T]) hasSameLengthAs [T, U] (ys: List[U]): Boolean = { - @tailrec def loop(xs: List[T], ys: List[U]): Boolean = - if (xs.isEmpty) ys.isEmpty - else ys.nonEmpty && loop(xs.tail, ys.tail) - loop(xs, ys) - } - - @tailrec - def (xs: List[T]) eqElements [T] (ys: List[AnyRef]): Boolean = xs match { - case x :: _ => - ys match { - case y :: _ => - x.asInstanceOf[AnyRef].eq(y) && - xs.tail.eqElements(ys.tail) - case _ => false - } - case nil => ys.isEmpty - } - - def (xs: List[T]) | [T] (ys: List[T]): List[T] = xs ::: (ys filterNot (xs contains _)) - - /** Intersection on lists seen as sets */ - def (xs: List[T]) & [T] (ys: List[T]): List[T] = xs filter (ys contains _) - - def (xss: List[List[T]]) nestedMap [T, U] (f: T => U): List[List[U]] = xss map (_ map f) - def (xss: List[List[T]]) nestedMapconserve [T, U](f: T => U): List[List[U]] = xss mapconserve (_ mapconserve f) - - def (text: Text) show given (ctx: 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. - */ - def (names: List[String]) containsPhase (phase: Phase): Boolean = - names.nonEmpty && { - phase match { - case phase: MegaPhase => phase.miniPhases.exists(names.containsPhase(_)) - case _ => - names exists { name => - name == "all" || { - val strippedName = name.stripSuffix("+") - val logNextPhase = name != strippedName - phase.phaseName.startsWith(strippedName) || - (logNextPhase && phase.prev.phaseName.startsWith(strippedName)) - } - } - } - } - - def (x: T) reporting [T] (op: T => String, printer: config.Printers.Printer = config.Printers.default): T = { - printer.println(op(x)) - x - } - - def (x: T) assertingErrorsReported [T] given Context: T = { - assert(the[Context].reporter.errorsReported) - x - } - - def (x: T) assertingErrorsReported [T] (msg: => String) given Context: T = { - assert(the[Context].reporter.errorsReported, msg) - x - } - - /** General purpose string formatting */ - def (sc: StringContext) i (args: Any*) given Context: String = - new StringFormatter(sc).assemble(args) - - /** Formatting for error messages: Like `i` but suppress follow-on - * error messages after the first one if some of their arguments are "non-sensical". - */ - def (sc: StringContext) em (args: Any*) given Context: String = - new ErrorMessageFormatter(sc).assemble(args) - - /** Formatting with added explanations: Like `em`, but add explanations to - * give more info about type variables and to disambiguate where needed. - */ - def (sc: StringContext) ex (args: Any*) given Context: String = - explained(sc.em(args: _*)) - - /** Formatter that adds syntax highlighting to all interpolated values */ - def (sc: StringContext) hl (args: Any*) given Context: String = - new SyntaxFormatter(sc).assemble(args).stripMargin - - def (arr: Array[T]) binarySearch [T <: AnyRef] (x: T): Int = - java.util.Arrays.binarySearch(arr.asInstanceOf[Array[Object]], x) - } - - /** Entrypoint for explanation string interpolator: - * - * ``` - * ex"disambiguate $tpe1 and $tpe2" - * ``` - */ - def explained(op: given Context => String) given Context: String = - printing.Formatting.explained(ctx => op given ctx) -}