diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 57164795b402..1e5e53a0ab14 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -2438,7 +2438,14 @@ object Types { private[this] var myRef: Type = null private[this] var computed = false def ref(implicit ctx: Context): Type = { - if (computed) assert(myRef != null) + if (computed) { + if (myRef == null) { + // if errors were reported previously handle this by throwing a CyclicReference + // instead of crashing immediately. A test case is neg/i6057.scala. + assert(ctx.reporter.errorsReported) + CyclicReference(NoDenotation) + } + } else { computed = true myRef = refFn(ctx) diff --git a/tests/neg/i6057.scala b/tests/neg/i6057.scala new file mode 100644 index 000000000000..7816e7b70908 --- /dev/null +++ b/tests/neg/i6057.scala @@ -0,0 +1,4 @@ +class i0[i1] { + type i2 <: i0[i2] + val i3: i2[i4] {} // error +} \ No newline at end of file