From 7352fc4a6fd7b3637bb7eb5f79f8a14f4e46a2b1 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 24 Sep 2015 16:16:22 +0200 Subject: underlyingChain -> underlyingIterator make successive underlying values an iterator (so that we do not run into a stackoverflow in case of cycles). --- src/dotty/tools/dotc/core/Types.scala | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/dotty/tools/dotc/core/Types.scala') diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index 8ad694ea2..e4f228915 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -806,12 +806,18 @@ object Types { case _ => NoType } - /** The chain of underlying types as long as type is a TypeProxy. + /** The iterator of underlying types as long as type is a TypeProxy. * Useful for diagnostics */ - def underlyingChain(implicit ctx: Context): List[Type] = this match { - case tp: TypeProxy => tp :: tp.underlying.underlyingChain - case _ => Nil + def underlyingIterator(implicit ctx: Context): Iterator[Type] = new Iterator[Type] { + var current = Type.this + var hasNext = true + def next = { + val res = current + hasNext = current.isInstanceOf[TypeProxy] + if (hasNext) current = current.asInstanceOf[TypeProxy].underlying + res + } } /** A prefix-less refined this or a termRef to a new skolem symbol -- cgit v1.2.3