Skip to content

Commit b7f5bf9

Browse files
authored
Merge pull request #2461 from dotty-staging/fix-#2088
Fix #2088: Test for simple cycle in type aliases
2 parents d97d35d + 58db939 commit b7f5bf9

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ object Checking {
208208
def isInteresting(prefix: Type): Boolean = prefix.stripTypeVar match {
209209
case NoPrefix => true
210210
case prefix: ThisType => sym.owner.isClass && prefix.cls.isContainedIn(sym.owner)
211-
case prefix: NamedType => !prefix.symbol.isStaticOwner && isInteresting(prefix.prefix)
211+
case prefix: NamedType =>
212+
(!sym.is(Private) && prefix.derivesFrom(sym.owner)) ||
213+
(!prefix.symbol.isStaticOwner && isInteresting(prefix.prefix))
212214
case SuperType(thistp, _) => isInteresting(thistp)
213215
case AndType(tp1, tp2) => isInteresting(tp1) || isInteresting(tp2)
214216
case OrType(tp1, tp2) => isInteresting(tp1) && isInteresting(tp2)

tests/neg/cycles.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class C {
2323

2424
class E {
2525
class F {
26-
type T <: x.type // old-error: not stable
26+
type T <: x.type // error
2727
val z: x.type = ??? // old-error: not stable
2828
}
2929
lazy val x: F#T = ???

tests/neg/i2088.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Base {
2+
type A = { // error: illegal cyclic reference: alias Object{m: Foo.B} of type B refers back to the type itself
3+
val m: Foo.A
4+
}
5+
6+
protected type B = { // error: illegal cyclic reference: alias Object{m: Foo.B} of type B refers back to the type itself
7+
val m: Foo.B
8+
}
9+
10+
private type C = {
11+
val m: Foo.C // error: type `C` is not a member of Foo.type
12+
}
13+
14+
type D = { // error: illegal cyclic reference: alias Object{m: Foo.E} of type D refers back to the type itself
15+
val m: Foo.E
16+
}
17+
18+
type E = {
19+
val m: Foo.D
20+
}
21+
}
22+
23+
object Foo extends Base

0 commit comments

Comments
 (0)