Skip to content

Commit d7bbdcd

Browse files
authored
Merge pull request #11465 from dotty-staging/fix-11464
Fix #11464: avoid expanding local paramRef in HKTypeLambda
2 parents 1dc4894 + 5ff7b10 commit d7bbdcd

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

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

Lines changed: 13 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+
@threadUnsafe lazy val localParamRefs = 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,25 @@ 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+
// 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+
tp
434438
case tp: SkolemType if partsToAvoid(Nil, tp.info).nonEmpty =>
435439
range(defn.NothingType, apply(tp.info))
436440
case tp: TypeVar if mapCtx.typerState.constraint.contains(tp) =>
437441
val lo = TypeComparer.instanceType(
438442
tp.origin, fromBelow = variance > 0 || variance == 0 && tp.hasLowerBound)(using mapCtx)
439443
val lo1 = apply(lo)
440444
if (lo1 ne lo) lo1 else tp
441-
case tp: LazyRef if isExpandingBounds =>
442-
emptyRange
445+
case tp: LazyRef =>
446+
if localParamRefs.contains(tp.ref) then tp
447+
else if isExpandingBounds then emptyRange
448+
else mapOver(tp)
449+
case tl: HKTypeLambda =>
450+
localParamRefs ++= tl.paramRefs
451+
mapOver(tl)
443452
case _ =>
444453
mapOver(tp)
445454
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2924,7 +2924,7 @@ object Types {
29242924
tp match {
29252925
case tp: TypeRef => apply(x, tp.prefix)
29262926
case tp: RecThis => RecType.this eq tp.binder
2927-
case tp: LazyRef => true // To be safe, assume a reference exists
2927+
case tp: LazyRef => this(x, tp.ref)
29282928
case _ => foldOver(x, tp)
29292929
}
29302930
}

compiler/test/dotc/pos-test-pickling.blacklist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,3 @@ i9793.scala
6060

6161
# lazy_implicit symbol has different position after pickling
6262
i8182.scala
63-

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)