Skip to content

Commit 021edbb

Browse files
committed
Fix #5876: Don't dereference pending LazyRefs when normalizing
In monitoredIsSubType, don't dereference pending LazyRefs when normalizing a type to check whether it is in the log of seen types.
1 parent 5cb511a commit 021edbb

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
210210
case t: LazyRef =>
211211
// Dereference a lazyref to detect underlying matching types, but
212212
// be careful not to get into an infinite recursion. If recursion count
213-
// exceeds `DerefLimit`, approximate with `NoType` instead.
213+
// exceeds `DerefLimit`, approximate with `t` instead.
214214
derefCount += 1
215-
if (derefCount >= DerefLimit) NoType
215+
if t.pending || derefCount >= DerefLimit then t
216216
else try mapOver(t.ref) finally derefCount -= 1
217217
case tp: TypeVar =>
218218
tp

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2578,6 +2578,8 @@ object Types {
25782578
private var myRef: Type = null
25792579
private var computed = false
25802580

2581+
def pending(using Context): Boolean = computed && myRef == null
2582+
25812583
def ref(implicit ctx: Context): Type =
25822584
if computed then
25832585
if myRef == null then

tests/pos-deep-subtype/i5876.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
type HasThisB[T] = HasThis { type This <: T }
2+
trait HasThis {
3+
type This >: this.type <: HasThisB[This]
4+
}
5+
6+
type FB[T] = F { type This <: T }
7+
class F extends HasThis {
8+
type This >: this.type <: FB[This]
9+
}

0 commit comments

Comments
 (0)