From 9d46ce1ee7da8f3a3fc9fe4d5c9b9cb6b58242c4 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 18 Mar 2019 10:51:35 +0100 Subject: [PATCH 1/2] Fix 6057: Be more forgiving in LazyRef checking if errors were reported previously --- compiler/src/dotty/tools/dotc/core/Types.scala | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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) From 67a0cecdf206ef7e9e23a61bfbd61048bc6cc1fd Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 18 Mar 2019 10:53:12 +0100 Subject: [PATCH 2/2] Add test case --- tests/neg/i6057.scala | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 tests/neg/i6057.scala 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