Skip to content

Commit b987eeb

Browse files
committed
Fix scala#11464: avoid expanding local paramRef in HKTypeLambda
1 parent 4f6d6f0 commit b987eeb

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

compiler/src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

tests/pos/i11464.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
trait Txn[T <: Txn[T]]
2+
3+
trait Adjunct
4+
5+
trait Type0
6+
trait Type[A1, Repr[~ <: Txn[~]] <: Expr[~, A1]] extends Type0
7+
8+
object Expr {
9+
def test(peer: Type0): Adjunct = {
10+
new AdjunctImpl(peer.asInstanceOf[Type[Any, ({ type R[~ <: Txn[~]] <: Expr[~, Any] }) # R]])
11+
}
12+
}
13+
14+
trait Expr[T <: Txn[T], +A]
15+
16+
class AdjunctImpl[A, E[~ <: Txn[~]] <: Expr[~, A]](tpe: Type[A, E]) extends Adjunct

0 commit comments

Comments
 (0)