Skip to content

Commit 7e16aca

Browse files
authored
Merge pull request #6104 from dotty-staging/fix-#6057ompt
Fix 6057: Be more forgiving in LazyRef checking
2 parents 3ab65ae + 67a0cec commit 7e16aca

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2438,7 +2438,14 @@ object Types {
24382438
private[this] var myRef: Type = null
24392439
private[this] var computed = false
24402440
def ref(implicit ctx: Context): Type = {
2441-
if (computed) assert(myRef != null)
2441+
if (computed) {
2442+
if (myRef == null) {
2443+
// if errors were reported previously handle this by throwing a CyclicReference
2444+
// instead of crashing immediately. A test case is neg/i6057.scala.
2445+
assert(ctx.reporter.errorsReported)
2446+
CyclicReference(NoDenotation)
2447+
}
2448+
}
24422449
else {
24432450
computed = true
24442451
myRef = refFn(ctx)

tests/neg/i6057.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class i0[i1] {
2+
type i2 <: i0[i2]
3+
val i3: i2[i4] {} // error
4+
}

0 commit comments

Comments
 (0)