From 59ea176b30fbb7af725707a64fe90574c8f47f33 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Mon, 2 Dec 2019 18:47:26 +0100 Subject: [PATCH] Fix #7602: Avoid infinite loop with anonymous projection `Type#findMember` has very careful logic for doing prefix substitution with a recursive type, but it turns out we don't need to run any of that if the prefix is already correct, and it avoids infinite loops in the added testcase. --- compiler/src/dotty/tools/dotc/core/Types.scala | 1 + tests/pos/i7602.scala | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 tests/pos/i7602.scala diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 7f1554c3dbec..25289c455127 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -614,6 +614,7 @@ object Types { } def goRec(tp: RecType) = if (tp.parent == null) NoDenotation + else if (tp eq pre) go(tp.parent) else { //println(s"find member $pre . $name in $tp") diff --git a/tests/pos/i7602.scala b/tests/pos/i7602.scala new file mode 100644 index 000000000000..0a380efc9d79 --- /dev/null +++ b/tests/pos/i7602.scala @@ -0,0 +1,7 @@ +object Test { + type X[T] = ({ type F[_]; type R = F[T]})#R + + trait Monad[F[_]] + type of[M[_[_]], T] = ({ type F[_]; type R = (given M[F]) => F[T]})#R + def foo(a: of[Monad, String]) = ??? +}