Skip to content

Commit d173cc0

Browse files
oderskyDarkDimius
authored andcommitted
Renaming clear->setNew
clear is wrong. E.g. clearTyperState does not clear the typerstate at all. It installs a fresh (i.e. cloned) copy of the previous one. clearScope is also wrong; it installs a new scope, does not clear the current one.
1 parent cac8c75 commit d173cc0

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,15 +316,15 @@ object Contexts {
316316
def setPeriod(period: Period): this.type = { this.period = period; this }
317317
def setMode(mode: Mode): this.type = { this.mode = mode; this }
318318
def setTyperState(typerState: TyperState): this.type = { this.typerState = typerState; this }
319-
def clearTyperState: this.type = setTyperState(typerState.fresh(isCommittable = true))
319+
def setNewTyperState: this.type = setTyperState(typerState.fresh(isCommittable = true))
320320
def setExploreTyperState: this.type = setTyperState(typerState.fresh(isCommittable = false))
321321
def setPrinterFn(printer: Context => Printer): this.type = { this.printerFn = printer; this }
322322
def setOwner(owner: Symbol): this.type = { assert(owner != NoSymbol); this.owner = owner; this }
323323
def setSettings(sstate: SettingsState): this.type = { this.sstate = sstate; this }
324324
def setCompilationUnit(compilationUnit: CompilationUnit): this.type = { this.compilationUnit = compilationUnit; this }
325325
def setTree(tree: Tree[_ >: Untyped]): this.type = { this.tree = tree; this }
326326
def setScope(scope: Scope): this.type = { this.scope = scope; this }
327-
def clearScope: this.type = { this.scope = newScope; this }
327+
def setNewScope: this.type = { this.scope = newScope; this }
328328
def setTypeAssigner(typeAssigner: TypeAssigner): this.type = { this.typeAssigner = typeAssigner; this }
329329
def setTyper(typer: Typer): this.type = { this.scope = typer.scope; setTypeAssigner(typer) }
330330
def setImportInfo(importInfo: ImportInfo): this.type = { this.importInfo = importInfo; this }

src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ trait Implicits { self: Typer =>
457457
pt)
458458
val generated1 = adapt(generated, pt)
459459
lazy val shadowing =
460-
typed(untpd.Ident(ref.name) withPos pos.toSynthetic, funProto)(nestedContext.clearTyperState)
460+
typed(untpd.Ident(ref.name) withPos pos.toSynthetic, funProto)(nestedContext.setNewTyperState)
461461
def refMatches(shadowing: Tree): Boolean =
462462
ref.symbol == closureBody(shadowing).symbol || {
463463
shadowing match {
@@ -485,7 +485,7 @@ trait Implicits { self: Typer =>
485485
val history = ctx.searchHistory nest wildProto
486486
val result =
487487
if (history eq ctx.searchHistory) divergingImplicit(ref)
488-
else typedImplicit(ref)(nestedContext.clearTyperState.setSearchHistory(history))
488+
else typedImplicit(ref)(nestedContext.setNewTyperState.setSearchHistory(history))
489489
result match {
490490
case fail: SearchFailure =>
491491
rankImplicits(pending1, acc)

src/dotty/tools/dotc/typer/Inferencing.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ trait Inferencing { this: Checking =>
3030
* Variables that are successfully minimized do not count as uninstantiated.
3131
*/
3232
def isFullyDefined(tp: Type, force: ForceDegree.Value)(implicit ctx: Context): Boolean = {
33-
val nestedCtx = ctx.fresh.clearTyperState
33+
val nestedCtx = ctx.fresh.setNewTyperState
3434
val result = new IsFullyDefinedAccumulator(force)(nestedCtx).process(tp)
3535
if (result) nestedCtx.typerState.commit()
3636
result

src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ class Namer { typer: Typer =>
292292

293293
/** A new context for the interior of a class */
294294
def inClassContext(selfInfo: DotClass /* Should be Type | Symbol*/)(implicit ctx: Context): Context = {
295-
val localCtx: Context = ctx.fresh.clearScope
295+
val localCtx: Context = ctx.fresh.setNewScope
296296
selfInfo match {
297297
case sym: Symbol if sym.exists && sym.name != nme.WILDCARD =>
298298
localCtx.scope.asInstanceOf[MutableScope].enter(sym)
@@ -385,14 +385,14 @@ class Namer { typer: Typer =>
385385
private def typeSig(sym: Symbol): Type = original match {
386386
case original: ValDef =>
387387
if (sym is Module) moduleValSig(sym)
388-
else valOrDefDefSig(original, sym, Nil, identity)(localContext(sym).clearScope)
388+
else valOrDefDefSig(original, sym, Nil, identity)(localContext(sym).setNewScope)
389389
case original: DefDef =>
390390
val typer1 = new Typer
391391
nestedTyper(sym) = typer1
392392
typer1.defDefSig(original, sym)(localContext(sym).setTyper(typer1))
393393
case original: TypeDef =>
394394
assert(!original.isClassDef)
395-
typeDefSig(original, sym)(localContext(sym).clearScope)
395+
typeDefSig(original, sym)(localContext(sym).setNewScope)
396396
case imp: Import =>
397397
try {
398398
val expr1 = typedAheadExpr(imp.expr, AnySelectionProto)

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
587587
assignType(cpy.CaseDef(tree, pat, guard1, body1), body1)
588588
}
589589
val doCase: () => CaseDef =
590-
() => caseRest(typedPattern(tree.pat, selType))(ctx.fresh.clearScope)
590+
() => caseRest(typedPattern(tree.pat, selType))(ctx.fresh.setNewScope)
591591
(doCase /: gadtSyms)((op, tsym) => tsym.withGADTFlexType(op))()
592592
}
593593

@@ -881,13 +881,13 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
881881
case tree: untpd.Bind => typedBind(tree, pt)
882882
case tree: untpd.ValDef =>
883883
if (tree.isEmpty) tpd.EmptyValDef
884-
else typedValDef(tree, sym)(localContext.clearScope)
884+
else typedValDef(tree, sym)(localContext.setNewScope)
885885
case tree: untpd.DefDef =>
886886
val typer1 = nestedTyper.remove(sym).get
887887
typer1.typedDefDef(tree, sym)(localContext.setTyper(typer1))
888888
case tree: untpd.TypeDef =>
889889
if (tree.isClassDef) typedClassDef(tree, sym.asClass)(localContext)
890-
else typedTypeDef(tree, sym)(localContext.clearScope)
890+
else typedTypeDef(tree, sym)(localContext.setNewScope)
891891
case _ => typedUnadapted(desugar(tree), pt)
892892
}
893893
}
@@ -909,7 +909,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
909909
case tree: untpd.Typed => typedTyped(tree, pt)
910910
case tree: untpd.NamedArg => typedNamedArg(tree, pt)
911911
case tree: untpd.Assign => typedAssign(tree, pt)
912-
case tree: untpd.Block => typedBlock(desugar.block(tree), pt)(ctx.fresh.clearScope)
912+
case tree: untpd.Block => typedBlock(desugar.block(tree), pt)(ctx.fresh.setNewScope)
913913
case tree: untpd.If => typedIf(tree, pt)
914914
case tree: untpd.Function => typedFunction(tree, pt)
915915
case tree: untpd.Closure => typedClosure(tree, pt)
@@ -992,7 +992,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
992992
typed(tree, pt)(ctx addMode Mode.Pattern)
993993

994994
def tryEither[T](op: Context => T)(fallBack: (T, TyperState) => T)(implicit ctx: Context) = {
995-
val nestedCtx = ctx.fresh.clearTyperState
995+
val nestedCtx = ctx.fresh.setNewTyperState
996996
val result = op(nestedCtx)
997997
if (nestedCtx.reporter.hasErrors)
998998
fallBack(result, nestedCtx.typerState)

0 commit comments

Comments
 (0)