Skip to content

Commit 689bd3e

Browse files
committed
Fix rebase breakage due to new shadowing check
New master checks for inherited symbols shadowing definitions, so it contained a number of changes where `ctx` in a map or an accumulator was renamed to `this.ctx`. All of these broke because we renamed `ctx` in map to `mapCtx`. Before, all these occurrences of `ctx` silently rebound in this PR to the enclosing `ctx` which is mostly OK, since the two contexts tend to be the same, but could also be wrong. So, the additional check has already apid for itself in increased robustness of refactorings!
1 parent dfd1fbe commit 689bd3e

File tree

7 files changed

+18
-18
lines changed

7 files changed

+18
-18
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ object desugar {
112112
val originalOwner = sym.owner
113113
def apply(tp: Type) = tp match {
114114
case tp: NamedType if tp.symbol.exists && (tp.symbol.owner eq originalOwner) =>
115-
val defctx = this.ctx.outersIterator.dropWhile(_.scope eq this.ctx.scope).next()
115+
val defctx = mapCtx.outersIterator.dropWhile(_.scope eq mapCtx.scope).next()
116116
var local = defctx.denotNamed(tp.name).suchThat(_.isParamOrAccessor).symbol
117117
if (local.exists) (defctx.owner.thisType select local).dealiasKeepAnnots
118118
else {

compiler/src/dotty/tools/dotc/reporting/messages.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,13 @@ object messages {
250250
// these are usually easier to analyze.
251251
object reported extends TypeMap:
252252
def setVariance(v: Int) = variance = v
253-
val constraint = this.ctx.typerState.constraint
253+
val constraint = mapCtx.typerState.constraint
254254
def apply(tp: Type): Type = tp match
255255
case tp: TypeParamRef =>
256256
constraint.entry(tp) match
257257
case bounds: TypeBounds =>
258-
if variance < 0 then apply(this.ctx.typeComparer.fullUpperBound(tp))
259-
else if variance > 0 then apply(this.ctx.typeComparer.fullLowerBound(tp))
258+
if variance < 0 then apply(mapCtx.typeComparer.fullUpperBound(tp))
259+
else if variance > 0 then apply(mapCtx.typeComparer.fullLowerBound(tp))
260260
else tp
261261
case NoType => tp
262262
case instType => apply(instType)

compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
138138
tp match {
139139
case tp: TypeRef if tp.symbol.isSplice =>
140140
if (tp.isTerm)
141-
this.ctx.error(i"splice outside quotes", pos)
141+
mapCtx.error(i"splice outside quotes", pos)
142142
if level > 0 then getQuoteTypeTags.getTagRef(tp.prefix.asInstanceOf[TermRef])
143143
else tp
144144
case tp: TypeRef if tp.symbol == defn.QuotedTypeClass.typeParams.head =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ object Implicits {
414414
case t: TypeParamRef =>
415415
constraint.entry(t) match {
416416
case NoType => t
417-
case bounds: TypeBounds => this.ctx.typeComparer.fullBounds(t)
417+
case bounds: TypeBounds => mapCtx.typeComparer.fullBounds(t)
418418
case t1 => t1
419419
}
420420
case t: TypeVar =>

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ object Inferencing {
6767
def apply(tvars: Set[TypeVar], tp: Type) = tp match {
6868
case tp: TypeVar
6969
if !tp.isInstantiated &&
70-
this.ctx.typeComparer.bounds(tp.origin)
70+
accCtx.typeComparer.bounds(tp.origin)
7171
.namedPartsWith(ref => params.contains(ref.symbol))
7272
.nonEmpty =>
7373
tvars + tp
@@ -172,13 +172,13 @@ object Inferencing {
172172
def traverse(tp: Type): Unit = {
173173
tp match {
174174
case param: TypeParamRef =>
175-
val constraint = this.ctx.typerState.constraint
175+
val constraint = accCtx.typerState.constraint
176176
constraint.entry(param) match {
177177
case TypeBounds(lo, hi)
178178
if (hi frozen_<:< lo) =>
179-
val inst = this.ctx.typeComparer.approximation(param, fromBelow = true)
179+
val inst = accCtx.typeComparer.approximation(param, fromBelow = true)
180180
typr.println(i"replace singleton $param := $inst")
181-
this.ctx.typerState.constraint = constraint.replace(param, inst)
181+
accCtx.typerState.constraint = constraint.replace(param, inst)
182182
case _ =>
183183
}
184184
case _ =>
@@ -333,7 +333,7 @@ object Inferencing {
333333
def setVariance(v: Int) = variance = v
334334
def apply(vmap: VarianceMap, t: Type): VarianceMap = t match {
335335
case t: TypeVar
336-
if !t.isInstantiated && this.ctx.typerState.constraint.contains(t) =>
336+
if !t.isInstantiated && accCtx.typerState.constraint.contains(t) =>
337337
val v = vmap(t)
338338
if (v == null) vmap.updated(t, variance)
339339
else if (v == variance || v == 0) vmap

compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ trait TypeAssigner {
123123
range(defn.NothingType, apply(classBound(tp.cls.classInfo)))
124124
case tp: SkolemType if partsToAvoid(mutable.Set.empty, tp.info).nonEmpty =>
125125
range(defn.NothingType, apply(tp.info))
126-
case tp: TypeVar if this.ctx.typerState.constraint.contains(tp) =>
127-
val lo = this.ctx.typeComparer.instanceType(
126+
case tp: TypeVar if mapCtx.typerState.constraint.contains(tp) =>
127+
val lo = mapCtx.typeComparer.instanceType(
128128
tp.origin, fromBelow = variance > 0 || variance == 0 && tp.hasLowerBound)
129129
val lo1 = apply(lo)
130130
if (lo1 ne lo) lo1 else tp

compiler/src/dotty/tools/dotc/typer/VarianceChecker.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ object VarianceChecker {
4444
.find(_.name.toTermName == paramName)
4545
.map(_.sourcePos)
4646
.getOrElse(tree.sourcePos)
47-
this.ctx.error(em"${paramVarianceStr}variant type parameter $paramName occurs in ${occursStr}variant position in ${tl.resType}", pos)
47+
accCtx.error(em"${paramVarianceStr}variant type parameter $paramName occurs in ${occursStr}variant position in ${tl.resType}", pos)
4848
}
4949
def apply(x: Boolean, t: Type) = x && {
5050
t match {
@@ -115,10 +115,10 @@ class VarianceChecker()(implicit ctx: Context) {
115115
val required = compose(relative, this.variance)
116116
def tvar_s = s"$tvar (${varianceLabel(tvar.flags)} ${tvar.showLocated})"
117117
def base_s = s"$base in ${base.owner}" + (if (base.owner.isClass) "" else " in " + base.owner.enclosingClass)
118-
this.ctx.log(s"verifying $tvar_s is ${varianceLabel(required)} at $base_s")
119-
this.ctx.log(s"relative variance: ${varianceLabel(relative)}")
120-
this.ctx.log(s"current variance: ${this.variance}")
121-
this.ctx.log(s"owner chain: ${base.ownersIterator.toList}")
118+
accCtx.log(s"verifying $tvar_s is ${varianceLabel(required)} at $base_s")
119+
accCtx.log(s"relative variance: ${varianceLabel(relative)}")
120+
accCtx.log(s"current variance: ${this.variance}")
121+
accCtx.log(s"owner chain: ${base.ownersIterator.toList}")
122122
if (tvar.isOneOf(required)) None
123123
else Some(VarianceError(tvar, required))
124124
}

0 commit comments

Comments
 (0)