@@ -401,6 +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 ]()
404405 def toAvoid (sym : Symbol ) = ! sym.isStatic && forbidden.contains(sym)
405406 def partsToAvoid = new NamedPartsAccumulator (tp => toAvoid(tp.symbol))
406407
@@ -429,17 +430,22 @@ object TypeOps:
429430 case _ =>
430431 emptyRange // should happen only in error cases
431432 }
432- case tp : ThisType if toAvoid(tp.cls) =>
433- range(defn. NothingType , apply(classBound(tp.cls.classInfo)))
433+ case tp : ThisType =>
434+ tp
434435 case tp : SkolemType if partsToAvoid(Nil , tp.info).nonEmpty =>
435436 range(defn.NothingType , apply(tp.info))
436437 case tp : TypeVar if mapCtx.typerState.constraint.contains(tp) =>
437438 val lo = TypeComparer .instanceType(
438439 tp.origin, fromBelow = variance > 0 || variance == 0 && tp.hasLowerBound)(using mapCtx)
439440 val lo1 = apply(lo)
440441 if (lo1 ne lo) lo1 else tp
441- case tp : LazyRef if isExpandingBounds =>
442- emptyRange
442+ case tp : LazyRef =>
443+ if locals.contains(tp.ref) then tp
444+ else if isExpandingBounds then emptyRange
445+ else mapOver(tp)
446+ case tl : HKTypeLambda =>
447+ locals ++= tl.paramRefs
448+ mapOver(tl)
443449 case _ =>
444450 mapOver(tp)
445451 }
0 commit comments