Skip to content

Commit e49bf81

Browse files
committed
Detect more cyclic references
Detect more cyclic references be generalizing the condition which prefixes are interesting.
1 parent 722dd87 commit e49bf81

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,11 @@ object Checking {
232232
// global symbols when doing the cyclicity check.
233233
def isInteresting(prefix: Type): Boolean = prefix.stripTypeVar match {
234234
case NoPrefix => true
235-
case prefix: ThisType => sym.owner.isClass && prefix.cls.isContainedIn(sym.owner)
235+
case prefix: ThisType =>
236+
sym.owner.isClass && (
237+
prefix.cls.isContainedIn(sym.owner) // sym reachable through outer references
238+
|| sym.owner.isContainedIn(prefix.cls) // sym reachable through member references
239+
)
236240
case prefix: NamedType =>
237241
(!sym.is(Private) && prefix.derivesFrom(sym.owner)) ||
238242
(!prefix.symbol.isStaticOwner && isInteresting(prefix.prefix))
@@ -242,6 +246,7 @@ object Checking {
242246
case _: RefinedOrRecType | _: AppliedType => true
243247
case _ => false
244248
}
249+
245250
if (isInteresting(pre)) {
246251
val pre1 = this(pre, false, false)
247252
if (locked.contains(tp) || tp.symbol.infoOrCompleter.isInstanceOf[NoCompleter])

tests/neg/i4368.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ object Test6 {
9898

9999
object Test7 {
100100
class Fix[F[_]] {
101-
class Foo { type R >: F[T] <: F[T] }
101+
class Foo { type R >: F[T] <: F[T] } // error: cyclic
102102
type T = F[Foo#R]
103103
}
104104

105105
object App {
106-
type Nat = Fix[Option]#T // error: too deep
106+
type Nat = Fix[Option]#T
107107
}
108108
}
109109
/*

0 commit comments

Comments
 (0)