Skip to content

Commit 04bec4b

Browse files
oderskyBlaisorblade
authored andcommitted
Detect more cyclic references
Detect more cyclic references be generalizing the condition which prefixes are interesting.
1 parent 8a4f24e commit 04bec4b

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
@@ -222,7 +222,11 @@ object Checking {
222222
// global symbols when doing the cyclicity check.
223223
def isInteresting(prefix: Type): Boolean = prefix.stripTypeVar match {
224224
case NoPrefix => true
225-
case prefix: ThisType => sym.owner.isClass && prefix.cls.isContainedIn(sym.owner)
225+
case prefix: ThisType =>
226+
sym.owner.isClass && (
227+
prefix.cls.isContainedIn(sym.owner) // sym reachable through outer references
228+
|| sym.owner.isContainedIn(prefix.cls) // sym reachable through member references
229+
)
226230
case prefix: NamedType =>
227231
(!sym.is(Private) && prefix.derivesFrom(sym.owner)) ||
228232
(!prefix.symbol.isStaticOwner && isInteresting(prefix.prefix))
@@ -232,6 +236,7 @@ object Checking {
232236
case _: RefinedOrRecType | _: AppliedType => true
233237
case _ => false
234238
}
239+
235240
if (isInteresting(pre)) {
236241
val pre1 = this(pre, false, false)
237242
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)