Skip to content

Fix #2088: Test for simple cycle in type aliases #2461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ object Checking {
def isInteresting(prefix: Type): Boolean = prefix.stripTypeVar match {
case NoPrefix => true
case prefix: ThisType => sym.owner.isClass && prefix.cls.isContainedIn(sym.owner)
case prefix: NamedType => !prefix.symbol.isStaticOwner && isInteresting(prefix.prefix)
case prefix: NamedType =>
(!sym.is(Private) && prefix.derivesFrom(sym.owner)) ||
(!prefix.symbol.isStaticOwner && isInteresting(prefix.prefix))
case SuperType(thistp, _) => isInteresting(thistp)
case AndType(tp1, tp2) => isInteresting(tp1) || isInteresting(tp2)
case OrType(tp1, tp2) => isInteresting(tp1) && isInteresting(tp2)
Expand Down
2 changes: 1 addition & 1 deletion tests/neg/cycles.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class C {

class E {
class F {
type T <: x.type // old-error: not stable
type T <: x.type // error
val z: x.type = ??? // old-error: not stable
}
lazy val x: F#T = ???
Expand Down
23 changes: 23 additions & 0 deletions tests/neg/i2088.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Base {
type A = { // error: illegal cyclic reference: alias Object{m: Foo.B} of type B refers back to the type itself
val m: Foo.A
}

protected type B = { // error: illegal cyclic reference: alias Object{m: Foo.B} of type B refers back to the type itself
val m: Foo.B
}

private type C = {
val m: Foo.C // error: type `C` is not a member of Foo.type
}

type D = { // error: illegal cyclic reference: alias Object{m: Foo.E} of type D refers back to the type itself
val m: Foo.E
}

type E = {
val m: Foo.D
}
}

object Foo extends Base