Skip to content

Commit c183e1f

Browse files
authored
Merge pull request #9120 from dotty-staging/fix-#9052
fix #9052: throw CyclicReference if LazyRef is already set
2 parents 345c8bc + e58ded9 commit c183e1f

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,10 @@ object SymDenotations {
490490
def recur(self: Type): Unit = self match
491491
case RefinedType(parent, name, rinfo) => rinfo match
492492
case TypeAlias(lzy: LazyRef) if name == this.name =>
493-
lzy.update(tp)
493+
if !lzy.completed then
494+
lzy.update(tp)
495+
else
496+
throw CyclicReference(this)
494497
case _ =>
495498
recur(parent)
496499
recur(owner.asClass.givenSelfType)

tests/neg/i9052/A.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
object impl:
2+
case object UNone
3+
4+
import impl._
5+
6+
opaque type UOption[+A] = (A | UNone.type) // error: Cyclic Reference involving UOption

tests/neg/i9052/B.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
val UNone: UOption[Nothing] = ??? // error: Cyclic Reference involving UOption

0 commit comments

Comments
 (0)