@@ -401,7 +401,7 @@ object TypeOps:
401
401
def avoid (tp : Type , symsToAvoid : => List [Symbol ])(using Context ): Type = {
402
402
val widenMap = new ApproximatingTypeMap {
403
403
@ threadUnsafe lazy val forbidden = symsToAvoid.toSet
404
- val locals = util.HashSet [Type ]()
404
+ @ threadUnsafe lazy val localParamRefs = util.HashSet [Type ]()
405
405
def toAvoid (sym : Symbol ) = ! sym.isStatic && forbidden.contains(sym)
406
406
def partsToAvoid = new NamedPartsAccumulator (tp => toAvoid(tp.symbol))
407
407
@@ -431,6 +431,10 @@ object TypeOps:
431
431
emptyRange // should happen only in error cases
432
432
}
433
433
case tp : ThisType =>
434
+ // ThisType is only used inside a class.
435
+ // Therefore, either they don't appear in the type to be avoided, or
436
+ // it must be a class that encloses the block whose type is to be avoided.
437
+ assert(! toAvoid(tp.cls))
434
438
tp
435
439
case tp : SkolemType if partsToAvoid(Nil , tp.info).nonEmpty =>
436
440
range(defn.NothingType , apply(tp.info))
@@ -440,11 +444,11 @@ object TypeOps:
440
444
val lo1 = apply(lo)
441
445
if (lo1 ne lo) lo1 else tp
442
446
case tp : LazyRef =>
443
- if locals .contains(tp.ref) then tp
447
+ if localParamRefs .contains(tp.ref) then tp
444
448
else if isExpandingBounds then emptyRange
445
449
else mapOver(tp)
446
450
case tl : HKTypeLambda =>
447
- locals ++= tl.paramRefs
451
+ localParamRefs ++= tl.paramRefs
448
452
mapOver(tl)
449
453
case _ =>
450
454
mapOver(tp)
0 commit comments