Skip to content

Commit 48cd101

Browse files
committed
ProtoTypes#wildApprox: fix LazyRef approximation
Before this commit, the output of `wildApprox(A)` where `A <: Sys[LazyRef(A)]` was `? <: Sys[LazyRef(() => wildApprox(A))]`. This lead to infinite subtyping checks. This is fixed by always approximating a LazyRef by an unbounded wildcard. Since we only create LazyRefs when we encounter a cycle, this should be safe. Fix #1103.
1 parent 4be70a5 commit 48cd101

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/dotty/tools/dotc/typer/ProtoTypes.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@ object ProtoTypes {
420420
WildcardType(tp1a.bounds | tp2a.bounds)
421421
else
422422
tp.derivedOrType(tp1a, tp2a)
423+
case tp: LazyRef =>
424+
WildcardType
423425
case tp: SelectionProto =>
424426
tp.derivedSelectionProto(tp.name, wildApprox(tp.memberProto), NoViewsAllowed)
425427
case tp: ViewProto =>

tests/pos/i1103.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Sys[S]
2+
class Foo[T <: Sys[T]] {
3+
val t: T = ???
4+
def foo[A <: Sys[A]](x: A = t) = x
5+
}

0 commit comments

Comments
 (0)