diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/Compiler.scala | 16 | ||||
-rw-r--r-- | src/dotty/tools/dotc/Driver.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/config/PathResolver.scala | 4 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Contexts.scala | 64 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Periods.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/Phases.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/SymDenotations.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/core/TypeComparer.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/printing/Disambiguation.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/transform/LazyVals.scala | 4 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Applications.scala | 4 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/FrontEnd.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Implicits.scala | 18 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Inferencing.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Namer.scala | 14 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/ProtoTypes.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 20 |
17 files changed, 81 insertions, 81 deletions
diff --git a/src/dotty/tools/dotc/Compiler.scala b/src/dotty/tools/dotc/Compiler.scala index 286ed3456..7b657b47b 100644 --- a/src/dotty/tools/dotc/Compiler.scala +++ b/src/dotty/tools/dotc/Compiler.scala @@ -42,18 +42,18 @@ class Compiler { ctx.usePhases(phases) val rootScope = new MutableScope val bootstrap = ctx.fresh - .withPeriod(Period(nextRunId, FirstPhaseId)) - .withScope(rootScope) + .setPeriod(Period(nextRunId, FirstPhaseId)) + .setScope(rootScope) rootScope.enter(ctx.definitions.RootPackage)(bootstrap) val start = bootstrap.fresh - .withOwner(defn.RootClass) - .withTyper(new Typer) - .withNewMode(Mode.ImplicitsEnabled) - .withTyperState(new MutableTyperState(ctx.typerState, new ConsoleReporter()(ctx), isCommittable = true)) + .setOwner(defn.RootClass) + .setTyper(new Typer) + .setMode(Mode.ImplicitsEnabled) + .setTyperState(new MutableTyperState(ctx.typerState, new ConsoleReporter()(ctx), isCommittable = true)) ctx.definitions.init(start) // set context of definitions to start def addImport(ctx: Context, sym: Symbol) = - ctx.fresh.withImportInfo(ImportInfo.rootImport(sym)(ctx)) - (start.withRunInfo(new RunInfo(start)) /: defn.RootImports)(addImport) + ctx.fresh.setImportInfo(ImportInfo.rootImport(sym)(ctx)) + (start.setRunInfo(new RunInfo(start)) /: defn.RootImports)(addImport) } def newRun(implicit ctx: Context): Run = { diff --git a/src/dotty/tools/dotc/Driver.scala b/src/dotty/tools/dotc/Driver.scala index 892e4cf7d..5bf65544a 100644 --- a/src/dotty/tools/dotc/Driver.scala +++ b/src/dotty/tools/dotc/Driver.scala @@ -24,7 +24,7 @@ abstract class Driver extends DotClass { def process(args: Array[String]): Reporter = { val summary = CompilerCommand.distill(args)(initCtx) - implicit val ctx: Context = initCtx.fresh.withSettings(summary.sstate) + implicit val ctx: Context = initCtx.fresh.setSettings(summary.sstate) val fileNames = CompilerCommand.checkUsage(summary) try { doCompile(newCompiler(), fileNames) diff --git a/src/dotty/tools/dotc/config/PathResolver.scala b/src/dotty/tools/dotc/config/PathResolver.scala index 73c045c77..34678ae2b 100644 --- a/src/dotty/tools/dotc/config/PathResolver.scala +++ b/src/dotty/tools/dotc/config/PathResolver.scala @@ -135,7 +135,7 @@ object PathResolver { def fromPathString(path: String)(implicit ctx: Context): JavaClassPath = { val settings = ctx.settings.classpath.update(path) - new PathResolver()(ctx.fresh.withSettings(settings)).result + new PathResolver()(ctx.fresh.setSettings(settings)).result } /** With no arguments, show the interesting values in Environment and Defaults. @@ -152,7 +152,7 @@ object PathResolver { val ArgsSummary(sstate, rest, errors) = ctx.settings.processArguments(args.toList, true) errors.foreach(println) - val pr = new PathResolver()(ctx.fresh.withSettings(sstate)) + val pr = new PathResolver()(ctx.fresh.setSettings(sstate)) println(" COMMAND: 'scala %s'".format(args.mkString(" "))) println("RESIDUAL: 'scala %s'\n".format(rest.mkString(" "))) pr.result.show diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala index da684ea9c..12a83185e 100644 --- a/src/dotty/tools/dotc/core/Contexts.scala +++ b/src/dotty/tools/dotc/core/Contexts.scala @@ -278,10 +278,10 @@ object Contexts { } final def withMode(mode: Mode): Context = - if (mode != this.mode) fresh.withNewMode(mode) else this + if (mode != this.mode) fresh.setMode(mode) else this final def withPhase(phase: PhaseId): Context = - if (this.phaseId == phaseId) this else fresh.withNewPhase(phase) + if (this.phaseId == phaseId) this else fresh.setPhase(phase) final def withPhase(phase: Phase): Context = withPhase(phase.id) @@ -306,36 +306,36 @@ object Contexts { * of its attributes using the with... methods. */ abstract class FreshContext extends Context { - def withPeriod(period: Period): this.type = { this.period = period; this } - def withNewMode(mode: Mode): this.type = { this.mode = mode; this } - def withTyperState(typerState: TyperState): this.type = { this.typerState = typerState; this } - def withNewTyperState: this.type = withTyperState(typerState.fresh(isCommittable = true)) - def withExploreTyperState: this.type = withTyperState(typerState.fresh(isCommittable = false)) - def withPrinterFn(printer: Context => Printer): this.type = { this.printerFn = printer; this } - def withOwner(owner: Symbol): this.type = { assert(owner != NoSymbol); this.owner = owner; this } - def withSettings(sstate: SettingsState): this.type = { this.sstate = sstate; this } - def withCompilationUnit(compilationUnit: CompilationUnit): this.type = { this.compilationUnit = compilationUnit; this } - def withTree(tree: Tree[_ >: Untyped]): this.type = { this.tree = tree; this } - def withScope(scope: Scope): this.type = { this.scope = scope; this } - def withNewScope: this.type = { this.scope = newScope; this } - def withTypeAssigner(typeAssigner: TypeAssigner): this.type = { this.typeAssigner = typeAssigner; this } - def withTyper(typer: Typer): this.type = { this.scope = typer.scope; withTypeAssigner(typer) } - def withImportInfo(importInfo: ImportInfo): this.type = { this.importInfo = importInfo; this } - def withRunInfo(runInfo: RunInfo): this.type = { this.runInfo = runInfo; this } - def withDiagnostics(diagnostics: Option[StringBuilder]): this.type = { this.diagnostics = diagnostics; this } - def withTypeComparerFn(tcfn: Context => TypeComparer): this.type = { this.typeComparer = tcfn(this); this } - def withSearchHistory(searchHistory: SearchHistory): this.type = { this.searchHistory = searchHistory; this } - def withMoreProperties(moreProperties: Map[String, Any]): this.type = { this.moreProperties = moreProperties; this } - - def withProperty(prop: (String, Any)): this.type = withMoreProperties(moreProperties + prop) - - def withNewPhase(pid: PhaseId): this.type = withPeriod(Period(runId, pid)) - def withNewPhase(phase: Phase): this.type = withNewPhase(phase.id) - - def withSetting[T](setting: Setting[T], value: T): this.type = - withSettings(setting.updateIn(sstate, value)) - - def withDebug = withSetting(base.settings.debug, true) + def setPeriod(period: Period): this.type = { this.period = period; this } + def setMode(mode: Mode): this.type = { this.mode = mode; this } + def setTyperState(typerState: TyperState): this.type = { this.typerState = typerState; this } + def clearTyperState: this.type = setTyperState(typerState.fresh(isCommittable = true)) + def setExploreTyperState: this.type = setTyperState(typerState.fresh(isCommittable = false)) + def setPrinterFn(printer: Context => Printer): this.type = { this.printerFn = printer; this } + def setOwner(owner: Symbol): this.type = { assert(owner != NoSymbol); this.owner = owner; this } + def setSettings(sstate: SettingsState): this.type = { this.sstate = sstate; this } + def setCompilationUnit(compilationUnit: CompilationUnit): this.type = { this.compilationUnit = compilationUnit; this } + def setTree(tree: Tree[_ >: Untyped]): this.type = { this.tree = tree; this } + def setScope(scope: Scope): this.type = { this.scope = scope; this } + def clearScope: this.type = { this.scope = newScope; this } + def setTypeAssigner(typeAssigner: TypeAssigner): this.type = { this.typeAssigner = typeAssigner; this } + def setTyper(typer: Typer): this.type = { this.scope = typer.scope; setTypeAssigner(typer) } + def setImportInfo(importInfo: ImportInfo): this.type = { this.importInfo = importInfo; this } + def setRunInfo(runInfo: RunInfo): this.type = { this.runInfo = runInfo; this } + def setDiagnostics(diagnostics: Option[StringBuilder]): this.type = { this.diagnostics = diagnostics; this } + def setTypeComparerFn(tcfn: Context => TypeComparer): this.type = { this.typeComparer = tcfn(this); this } + def setSearchHistory(searchHistory: SearchHistory): this.type = { this.searchHistory = searchHistory; this } + def setMoreProperties(moreProperties: Map[String, Any]): this.type = { this.moreProperties = moreProperties; this } + + def setProperty(prop: (String, Any)): this.type = setMoreProperties(moreProperties + prop) + + def setPhase(pid: PhaseId): this.type = setPeriod(Period(runId, pid)) + def setPhase(phase: Phase): this.type = setPhase(phase.id) + + def setSetting[T](setting: Setting[T], value: T): this.type = + setSettings(setting.updateIn(sstate, value)) + + def setDebug = setSetting(base.settings.debug, true) } /** A class defining the initial context with given context base diff --git a/src/dotty/tools/dotc/core/Periods.scala b/src/dotty/tools/dotc/core/Periods.scala index 6e1522e26..370cc2b96 100644 --- a/src/dotty/tools/dotc/core/Periods.scala +++ b/src/dotty/tools/dotc/core/Periods.scala @@ -19,7 +19,7 @@ abstract class Periods extends DotClass { self: Context => /** Execute `op` at given period */ def atPeriod[T](pd: Period)(op: Context => T): T = - op(ctx.fresh.withPeriod(pd)) + op(ctx.fresh.setPeriod(pd)) /** Execute `op` at given phase id */ def atPhase[T](pid: PhaseId)(op: Context => T): T = diff --git a/src/dotty/tools/dotc/core/Phases.scala b/src/dotty/tools/dotc/core/Phases.scala index ee993b890..3de42fb4e 100644 --- a/src/dotty/tools/dotc/core/Phases.scala +++ b/src/dotty/tools/dotc/core/Phases.scala @@ -163,7 +163,7 @@ object Phases { def run(implicit ctx: Context): Unit def runOn(units: List[CompilationUnit])(implicit ctx: Context): Unit = - for (unit <- units) run(ctx.fresh.withNewPhase(this).withCompilationUnit(unit)) + for (unit <- units) run(ctx.fresh.setPhase(this).setCompilationUnit(unit)) def description: String = name diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index 248cf3de3..b5c7ea539 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -1356,7 +1356,7 @@ object SymDenotations { val (location, src) = if (file != null) (s" in $file", file.toString) else ("", "the signature") - val name = ctx.fresh.withSetting(ctx.settings.debugNames, true).nameString(denot.name) + val name = ctx.fresh.setSetting(ctx.settings.debugNames, true).nameString(denot.name) ctx.error( s"""|bad symbolic reference. A signature$location |refers to $name in ${denot.owner.showKind} ${denot.owner.showFullName} which is not available. diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala index ce1c1e869..cab09826b 100644 --- a/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/src/dotty/tools/dotc/core/TypeComparer.scala @@ -1134,7 +1134,7 @@ object TypeComparer { /** Show trace of comparison operations when performing `op` as result string */ def explained[T](op: Context => T)(implicit ctx: Context): String = { - val nestedCtx = ctx.fresh.withTypeComparerFn(new ExplainingTypeComparer(_)) + val nestedCtx = ctx.fresh.setTypeComparerFn(new ExplainingTypeComparer(_)) op(nestedCtx) nestedCtx.typeComparer.toString } diff --git a/src/dotty/tools/dotc/printing/Disambiguation.scala b/src/dotty/tools/dotc/printing/Disambiguation.scala index b830b353a..baacee42f 100644 --- a/src/dotty/tools/dotc/printing/Disambiguation.scala +++ b/src/dotty/tools/dotc/printing/Disambiguation.scala @@ -75,7 +75,7 @@ object Disambiguation { def disambiguated(op: Context => String)(implicit ctx: Context): String = { val dctx = ctx.printer match { case dp: Printer => ctx - case _ => ctx.fresh.withPrinterFn(newPrinter) + case _ => ctx.fresh.setPrinterFn(newPrinter) } val res = op(dctx) dctx.printer match { diff --git a/src/dotty/tools/dotc/transform/LazyVals.scala b/src/dotty/tools/dotc/transform/LazyVals.scala index ffc2096f1..28a8d12d9 100644 --- a/src/dotty/tools/dotc/transform/LazyVals.scala +++ b/src/dotty/tools/dotc/transform/LazyVals.scala @@ -249,7 +249,7 @@ class LazyValTranformContext { val flagSymbol = ctx.newSymbol(methodSymbol, "flag".toTermName, Flags.Mutable & Flags.Synthetic, defn.LongType) val flagDef = ValDef(flagSymbol, Literal(Constant(0L))) - val thiz = This(claz)(ctx.fresh.withOwner(claz)) + val thiz = This(claz)(ctx.fresh.setOwner(claz)) val resultSymbol = ctx.newSymbol(methodSymbol, "result".toTermName, Flags.Mutable & Flags.Synthetic, tp) val resultDef = ValDef(resultSymbol, Literal(initValue(tp.widen))) @@ -313,7 +313,7 @@ class LazyValTranformContext { val tpe = x.tpe.widen val claz = x.symbol.owner.asClass - val thiz = This(claz)(ctx.fresh.withOwner(claz)) + val thiz = This(claz)(ctx.fresh.setOwner(claz)) val companion = claz.companionModule val helperModule = ctx.requiredModule("dotty.runtime.LazyVals") val getOffset = Select(Ident(helperModule.termRef), LazyVals.Names.getOffset.toTermName) diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala index 46a6ebf66..9a21e1c54 100644 --- a/src/dotty/tools/dotc/typer/Applications.scala +++ b/src/dotty/tools/dotc/typer/Applications.scala @@ -712,7 +712,7 @@ trait Applications extends Compatibility { self: Typer => * @param resultType The expected result type of the application */ def isApplicable(methRef: TermRef, targs: List[Type], args: List[Tree], resultType: Type)(implicit ctx: Context): Boolean = { - val nestedContext = ctx.fresh.withExploreTyperState + val nestedContext = ctx.fresh.setExploreTyperState new ApplicableToTrees(methRef, targs, args, resultType)(nestedContext).success } @@ -720,7 +720,7 @@ trait Applications extends Compatibility { self: Typer => * @param resultType The expected result type of the application */ def isApplicable(methRef: TermRef, args: List[Type], resultType: Type)(implicit ctx: Context): Boolean = { - val nestedContext = ctx.fresh.withExploreTyperState + val nestedContext = ctx.fresh.setExploreTyperState new ApplicableToTypes(methRef, args, resultType)(nestedContext).success } diff --git a/src/dotty/tools/dotc/typer/FrontEnd.scala b/src/dotty/tools/dotc/typer/FrontEnd.scala index 0161c1f6f..697830fb1 100644 --- a/src/dotty/tools/dotc/typer/FrontEnd.scala +++ b/src/dotty/tools/dotc/typer/FrontEnd.scala @@ -41,7 +41,7 @@ class FrontEnd extends Phase { } override def runOn(units: List[CompilationUnit])(implicit ctx: Context): Unit = { - val unitContexts = units map (unit => ctx.fresh.withCompilationUnit(unit)) + val unitContexts = units map (unit => ctx.fresh.setCompilationUnit(unit)) unitContexts foreach (parse(_)) record("parsedTrees", ast.Trees.ntrees) unitContexts foreach (enterSyms(_)) diff --git a/src/dotty/tools/dotc/typer/Implicits.scala b/src/dotty/tools/dotc/typer/Implicits.scala index fe1c938c9..8990d21a2 100644 --- a/src/dotty/tools/dotc/typer/Implicits.scala +++ b/src/dotty/tools/dotc/typer/Implicits.scala @@ -50,13 +50,13 @@ object Implicits { case mt: MethodType => mt.isImplicit || mt.paramTypes.length != 1 || - !(argType <:< mt.paramTypes.head)(ctx.fresh.withExploreTyperState) + !(argType <:< mt.paramTypes.head)(ctx.fresh.setExploreTyperState) case poly: PolyType => poly.resultType match { case mt: MethodType => mt.isImplicit || mt.paramTypes.length != 1 || - !(argType <:< wildApprox(mt.paramTypes.head)(ctx.fresh.withExploreTyperState)) + !(argType <:< wildApprox(mt.paramTypes.head)(ctx.fresh.setExploreTyperState)) case rtp => discardForView(wildApprox(rtp), argType) } @@ -90,7 +90,7 @@ object Implicits { } if (refs.isEmpty) refs - else refs filter (refMatches(_)(ctx.fresh.withExploreTyperState.addMode(Mode.TypevarsMissContext))) // create a defensive copy of ctx to avoid constraint pollution + else refs filter (refMatches(_)(ctx.fresh.setExploreTyperState.addMode(Mode.TypevarsMissContext))) // create a defensive copy of ctx to avoid constraint pollution } } @@ -370,7 +370,7 @@ trait Implicits { self: Typer => } case _ => } - inferView(dummyTreeOfType(from), to)(ctx.fresh.withExploreTyperState).isInstanceOf[SearchSuccess] + inferView(dummyTreeOfType(from), to)(ctx.fresh.setExploreTyperState).isInstanceOf[SearchSuccess] } ) @@ -419,7 +419,7 @@ trait Implicits { self: Typer => /** An implicit search; parameters as in `inferImplicit` */ class ImplicitSearch(protected val pt: Type, protected val argument: Tree, pos: Position)(implicit ctx: Context) { - private def nestedContext = ctx.fresh.withNewMode(ctx.mode &~ Mode.ImplicitsEnabled) + private def nestedContext = ctx.fresh.setMode(ctx.mode &~ Mode.ImplicitsEnabled) private def implicitProto(resultType: Type, f: Type => Type) = if (argument.isEmpty) f(resultType) else ViewProto(f(argument.tpe.widen), f(resultType)) @@ -457,7 +457,7 @@ trait Implicits { self: Typer => pt) val generated1 = adapt(generated, pt) lazy val shadowing = - typed(untpd.Ident(ref.name) withPos pos.toSynthetic, funProto)(nestedContext.withNewTyperState) + typed(untpd.Ident(ref.name) withPos pos.toSynthetic, funProto)(nestedContext.clearTyperState) def refMatches(shadowing: Tree): Boolean = ref.symbol == closureBody(shadowing).symbol || { shadowing match { @@ -485,12 +485,12 @@ trait Implicits { self: Typer => val history = ctx.searchHistory nest wildProto val result = if (history eq ctx.searchHistory) divergingImplicit(ref) - else typedImplicit(ref)(nestedContext.withNewTyperState.withSearchHistory(history)) + else typedImplicit(ref)(nestedContext.clearTyperState.setSearchHistory(history)) result match { case fail: SearchFailure => rankImplicits(pending1, acc) case best: SearchSuccess => - val newPending = pending1 filter (isAsGood(_, best.ref)(nestedContext.withExploreTyperState)) + val newPending = pending1 filter (isAsGood(_, best.ref)(nestedContext.setExploreTyperState)) rankImplicits(newPending, best :: acc) } case nil => acc @@ -499,7 +499,7 @@ trait Implicits { self: Typer => /** Convert a (possibly empty) list of search successes into a single search result */ def condense(hits: List[SearchSuccess]): SearchResult = hits match { case best :: alts => - alts find (alt => isAsGood(alt.ref, best.ref)(ctx.fresh.withExploreTyperState)) match { + alts find (alt => isAsGood(alt.ref, best.ref)(ctx.fresh.setExploreTyperState)) match { case Some(alt) => /* !!! DEBUG println(i"ambiguous refs: ${hits map (_.ref) map (_.show) mkString ", "}") diff --git a/src/dotty/tools/dotc/typer/Inferencing.scala b/src/dotty/tools/dotc/typer/Inferencing.scala index 6d9afecab..9c4ce232e 100644 --- a/src/dotty/tools/dotc/typer/Inferencing.scala +++ b/src/dotty/tools/dotc/typer/Inferencing.scala @@ -30,7 +30,7 @@ trait Inferencing { this: Checking => * Variables that are successfully minimized do not count as uninstantiated. */ def isFullyDefined(tp: Type, force: ForceDegree.Value)(implicit ctx: Context): Boolean = { - val nestedCtx = ctx.fresh.withNewTyperState + val nestedCtx = ctx.fresh.clearTyperState val result = new IsFullyDefinedAccumulator(force)(nestedCtx).process(tp) if (result) nestedCtx.typerState.commit() result diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index 361de802c..e81949f05 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -288,11 +288,11 @@ class Namer { typer: Typer => /** A new context that summarizes an import statement */ def importContext(sym: Symbol, selectors: List[Tree])(implicit ctx: Context) = - ctx.fresh.withImportInfo(new ImportInfo(sym, selectors)) + ctx.fresh.setImportInfo(new ImportInfo(sym, selectors)) /** A new context for the interior of a class */ def inClassContext(selfInfo: DotClass /* Should be Type | Symbol*/)(implicit ctx: Context): Context = { - val localCtx: Context = ctx.fresh.withNewScope + val localCtx: Context = ctx.fresh.clearScope selfInfo match { case sym: Symbol if sym.exists && sym.name != nme.WILDCARD => localCtx.scope.asInstanceOf[MutableScope].enter(sym) @@ -330,7 +330,7 @@ class Namer { typer: Typer => def indexExpanded(stat: Tree)(implicit ctx: Context): Context = expanded(stat) match { case pcl: PackageDef => val pkg = createPackageSymbol(pcl.pid) - index(pcl.stats)(ctx.fresh.withOwner(pkg.moduleClass)) + index(pcl.stats)(ctx.fresh.setOwner(pkg.moduleClass)) invalidateCompanions(pkg, Trees.flatten(pcl.stats map expanded)) ctx case imp: Import => @@ -380,19 +380,19 @@ class Namer { typer: Typer => /** The completer of a symbol defined by a member def or import (except ClassSymbols) */ class Completer(val original: Tree)(implicit ctx: Context) extends LazyType { - protected def localContext(owner: Symbol) = ctx.fresh.withOwner(owner).withTree(original) + protected def localContext(owner: Symbol) = ctx.fresh.setOwner(owner).setTree(original) private def typeSig(sym: Symbol): Type = original match { case original: ValDef => if (sym is Module) moduleValSig(sym) - else valOrDefDefSig(original, sym, Nil, identity)(localContext(sym).withNewScope) + else valOrDefDefSig(original, sym, Nil, identity)(localContext(sym).clearScope) case original: DefDef => val typer1 = new Typer nestedTyper(sym) = typer1 - typer1.defDefSig(original, sym)(localContext(sym).withTyper(typer1)) + typer1.defDefSig(original, sym)(localContext(sym).setTyper(typer1)) case original: TypeDef => assert(!original.isClassDef) - typeDefSig(original, sym)(localContext(sym).withNewScope) + typeDefSig(original, sym)(localContext(sym).clearScope) case imp: Import => try { val expr1 = typedAheadExpr(imp.expr, AnySelectionProto) diff --git a/src/dotty/tools/dotc/typer/ProtoTypes.scala b/src/dotty/tools/dotc/typer/ProtoTypes.scala index 16fcc9db7..16869454f 100644 --- a/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -38,7 +38,7 @@ object ProtoTypes { /** Test compatibility after normalization in a fresh typerstate. */ def normalizedCompatible(tp: Type, pt: Type)(implicit ctx: Context) = { - val nestedCtx = ctx.fresh.withExploreTyperState + val nestedCtx = ctx.fresh.setExploreTyperState isCompatible(normalize(tp, pt)(nestedCtx), pt)(nestedCtx) } diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 7c301a7f1..0ba53f8c0 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -587,7 +587,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit assignType(cpy.CaseDef(tree, pat, guard1, body1), body1) } val doCase: () => CaseDef = - () => caseRest(typedPattern(tree.pat, selType))(ctx.fresh.withNewScope) + () => caseRest(typedPattern(tree.pat, selType))(ctx.fresh.clearScope) (doCase /: gadtSyms)((op, tsym) => tsym.withGADTFlexType(op))() } @@ -835,7 +835,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit val pid1 = typedExpr(tree.pid, AnySelectionProto) val pkg = pid1.symbol val packageContext = - if (pkg is Package) ctx.fresh.withOwner(pkg.moduleClass).withTree(tree) + if (pkg is Package) ctx.fresh.setOwner(pkg.moduleClass).setTree(tree) else { ctx.error(i"$pkg is not a packge", tree.pos) ctx @@ -872,8 +872,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit NoSymbol } def localContext = { - val freshCtx = ctx.fresh.withTree(xtree) - if (sym.exists) freshCtx.withOwner(sym) + val freshCtx = ctx.fresh.setTree(xtree) + if (sym.exists) freshCtx.setOwner(sym) else freshCtx // can happen for self defs } @@ -884,13 +884,13 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit case tree: untpd.Bind => typedBind(tree, pt) case tree: untpd.ValDef => if (tree.isEmpty) tpd.EmptyValDef - else typedValDef(tree, sym)(localContext.withNewScope) + else typedValDef(tree, sym)(localContext.clearScope) case tree: untpd.DefDef => val typer1 = nestedTyper.remove(sym).get - typer1.typedDefDef(tree, sym)(localContext.withTyper(typer1)) + typer1.typedDefDef(tree, sym)(localContext.setTyper(typer1)) case tree: untpd.TypeDef => if (tree.isClassDef) typedClassDef(tree, sym.asClass)(localContext) - else typedTypeDef(tree, sym)(localContext.withNewScope) + else typedTypeDef(tree, sym)(localContext.clearScope) case _ => typedUnadapted(desugar(tree), pt) } @@ -904,7 +904,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit case tree: untpd.Typed => typedTyped(tree, pt) case tree: untpd.NamedArg => typedNamedArg(tree, pt) case tree: untpd.Assign => typedAssign(tree, pt) - case tree: untpd.Block => typedBlock(desugar.block(tree), pt)(ctx.fresh.withNewScope) + case tree: untpd.Block => typedBlock(desugar.block(tree), pt)(ctx.fresh.clearScope) case tree: untpd.If => typedIf(tree, pt) case tree: untpd.Function => typedFunction(tree, pt) case tree: untpd.Closure => typedClosure(tree, pt) @@ -970,7 +970,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit case Thicket(stats) :: rest => traverse(stats ++ rest) case stat :: rest => - val nestedCtx = if (exprOwner == ctx.owner) ctx else ctx.fresh.withOwner(exprOwner) + val nestedCtx = if (exprOwner == ctx.owner) ctx else ctx.fresh.setOwner(exprOwner) buf += typed(stat)(nestedCtx) traverse(rest) case nil => @@ -987,7 +987,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit typed(tree, pt)(ctx addMode Mode.Pattern) def tryEither[T](op: Context => T)(fallBack: (T, TyperState) => T)(implicit ctx: Context) = { - val nestedCtx = ctx.fresh.withNewTyperState + val nestedCtx = ctx.fresh.clearTyperState val result = op(nestedCtx) if (nestedCtx.reporter.hasErrors) fallBack(result, nestedCtx.typerState) |