From b65f689af77e15fba5e36e1d943e818b34b75bb4 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Sat, 15 Jul 2023 13:39:23 +0100 Subject: [PATCH] Handle recursion in collectParts --- compiler/src/dotty/tools/dotc/typer/Implicits.scala | 3 ++- tests/neg/i18171.scala | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/neg/i18171.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Implicits.scala b/compiler/src/dotty/tools/dotc/typer/Implicits.scala index d5dffff30afb..91d946ad1c63 100644 --- a/compiler/src/dotty/tools/dotc/typer/Implicits.scala +++ b/compiler/src/dotty/tools/dotc/typer/Implicits.scala @@ -604,7 +604,7 @@ trait ImplicitRunInfo: private var parts: mutable.LinkedHashSet[Type] = _ private val partSeen = util.HashSet[Type]() - def traverse(t: Type) = + def traverse(t: Type) = try if partSeen.contains(t) then () else if implicitScopeCache.contains(t) then parts += t else @@ -643,6 +643,7 @@ trait ImplicitRunInfo: traverse(mt) case t => traverseChildren(t) + catch case ex: Throwable => handleRecursive("collectParts of", t.show, ex) def apply(tp: Type): collection.Set[Type] = parts = mutable.LinkedHashSet() diff --git a/tests/neg/i18171.scala b/tests/neg/i18171.scala new file mode 100644 index 000000000000..d269f70beb30 --- /dev/null +++ b/tests/neg/i18171.scala @@ -0,0 +1,10 @@ +type BAZ[T] = T match + case Any => DFVal[BAZREC[T]] + +type BAZREC[T] = T match + case NonEmptyTuple => Tuple.Map[T, BAZ] + +trait DFVal[T] + +def foo(relIdx: BAZ[Any]): Unit = + relIdx.bar // error