From 58db9399592ccfe91d6c42d0c58a187a008c4baf Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 17 May 2017 17:14:37 +0200 Subject: [PATCH] Fix #2088: Test for simple cycle in type aliases --- .../src/dotty/tools/dotc/typer/Checking.scala | 4 +++- tests/neg/cycles.scala | 2 +- tests/neg/i2088.scala | 23 +++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 tests/neg/i2088.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index e33652268e25..47beea57e38c 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -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) diff --git a/tests/neg/cycles.scala b/tests/neg/cycles.scala index f9e546acac35..b77d253bd527 100644 --- a/tests/neg/cycles.scala +++ b/tests/neg/cycles.scala @@ -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 = ??? diff --git a/tests/neg/i2088.scala b/tests/neg/i2088.scala new file mode 100644 index 000000000000..ab5f15d47b5b --- /dev/null +++ b/tests/neg/i2088.scala @@ -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