From 48cd10159573150ed41c86d45c259cf6ad1a0c8e Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Thu, 18 Feb 2016 18:44:00 +0100 Subject: [PATCH] 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. --- src/dotty/tools/dotc/typer/ProtoTypes.scala | 2 ++ tests/pos/i1103.scala | 5 +++++ 2 files changed, 7 insertions(+) create mode 100644 tests/pos/i1103.scala diff --git a/src/dotty/tools/dotc/typer/ProtoTypes.scala b/src/dotty/tools/dotc/typer/ProtoTypes.scala index 8a758bcc82e2..7997d1cf4fba 100644 --- a/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -420,6 +420,8 @@ object ProtoTypes { WildcardType(tp1a.bounds | tp2a.bounds) else tp.derivedOrType(tp1a, tp2a) + case tp: LazyRef => + WildcardType case tp: SelectionProto => tp.derivedSelectionProto(tp.name, wildApprox(tp.memberProto), NoViewsAllowed) case tp: ViewProto => diff --git a/tests/pos/i1103.scala b/tests/pos/i1103.scala new file mode 100644 index 000000000000..dcc391a6a1ac --- /dev/null +++ b/tests/pos/i1103.scala @@ -0,0 +1,5 @@ +class Sys[S] +class Foo[T <: Sys[T]] { + val t: T = ??? + def foo[A <: Sys[A]](x: A = t) = x +}