@@ -401,7 +401,7 @@ object TypeOps:
401401 def avoid (tp : Type , symsToAvoid : => List [Symbol ])(using Context ): Type = {
402402 val widenMap = new ApproximatingTypeMap {
403403 @ threadUnsafe lazy val forbidden = symsToAvoid.toSet
404- val locals = util.HashSet [Type ]()
404+ @ threadUnsafe lazy val localParamRefs = util.HashSet [Type ]()
405405 def toAvoid (sym : Symbol ) = ! sym.isStatic && forbidden.contains(sym)
406406 def partsToAvoid = new NamedPartsAccumulator (tp => toAvoid(tp.symbol))
407407
@@ -431,6 +431,9 @@ object TypeOps:
431431 emptyRange // should happen only in error cases
432432 }
433433 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.
434437 tp
435438 case tp : SkolemType if partsToAvoid(Nil , tp.info).nonEmpty =>
436439 range(defn.NothingType , apply(tp.info))
@@ -440,11 +443,11 @@ object TypeOps:
440443 val lo1 = apply(lo)
441444 if (lo1 ne lo) lo1 else tp
442445 case tp : LazyRef =>
443- if locals .contains(tp.ref) then tp
446+ if localParamRefs .contains(tp.ref) then tp
444447 else if isExpandingBounds then emptyRange
445448 else mapOver(tp)
446449 case tl : HKTypeLambda =>
447- locals ++= tl.paramRefs
450+ localParamRefs ++= tl.paramRefs
448451 mapOver(tl)
449452 case _ =>
450453 mapOver(tp)
0 commit comments