diff --git a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala index acb545efdca4..c42db67be990 100644 --- a/compiler/src/dotty/tools/dotc/core/TypeComparer.scala +++ b/compiler/src/dotty/tools/dotc/core/TypeComparer.scala @@ -210,9 +210,9 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w case t: LazyRef => // Dereference a lazyref to detect underlying matching types, but // be careful not to get into an infinite recursion. If recursion count - // exceeds `DerefLimit`, approximate with `NoType` instead. + // exceeds `DerefLimit`, approximate with `t` instead. derefCount += 1 - if (derefCount >= DerefLimit) NoType + if t.evaluating || derefCount >= DerefLimit then t else try mapOver(t.ref) finally derefCount -= 1 case tp: TypeVar => tp diff --git a/tests/pos-deep-subtype/i5876.scala b/tests/pos-deep-subtype/i5876.scala new file mode 100644 index 000000000000..e8a510135dc4 --- /dev/null +++ b/tests/pos-deep-subtype/i5876.scala @@ -0,0 +1,9 @@ +type HasThisB[T] = HasThis { type This <: T } +trait HasThis { + type This >: this.type <: HasThisB[This] +} + +type FB[T] = F { type This <: T } +class F extends HasThis { + type This >: this.type <: FB[This] +} \ No newline at end of file