@@ -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,9 @@ 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.
434
437
tp
435
438
case tp : SkolemType if partsToAvoid(Nil , tp.info).nonEmpty =>
436
439
range(defn.NothingType , apply(tp.info))
@@ -440,11 +443,11 @@ object TypeOps:
440
443
val lo1 = apply(lo)
441
444
if (lo1 ne lo) lo1 else tp
442
445
case tp : LazyRef =>
443
- if locals .contains(tp.ref) then tp
446
+ if localParamRefs .contains(tp.ref) then tp
444
447
else if isExpandingBounds then emptyRange
445
448
else mapOver(tp)
446
449
case tl : HKTypeLambda =>
447
- locals ++= tl.paramRefs
450
+ localParamRefs ++= tl.paramRefs
448
451
mapOver(tl)
449
452
case _ =>
450
453
mapOver(tp)
0 commit comments