From 3d6534f1d3f1abe5ec9c27a7d0452142ae7d3d86 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Mon, 20 Oct 2014 11:19:50 +0200 Subject: [PATCH] Detect cycles involving types bounded by singleton types This fixes #193. --- src/dotty/tools/dotc/typer/Checking.scala | 3 +++ test/dotc/tests.scala | 2 ++ tests/neg/cycles.scala | 25 +++++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/src/dotty/tools/dotc/typer/Checking.scala b/src/dotty/tools/dotc/typer/Checking.scala index f3e9fda7443b..4466e05edff6 100644 --- a/src/dotty/tools/dotc/typer/Checking.scala +++ b/src/dotty/tools/dotc/typer/Checking.scala @@ -105,6 +105,9 @@ object Checking { } def apply(tp: Type) = tp match { + case tp: TermRef => + this(tp.info) + mapOver(tp) case tp @ RefinedType(parent, name) => val parent1 = this(parent) val saved = cycleOK diff --git a/test/dotc/tests.scala b/test/dotc/tests.scala index 71a1600bb7da..37cbb16b395e 100644 --- a/test/dotc/tests.scala +++ b/test/dotc/tests.scala @@ -100,6 +100,8 @@ class tests extends CompilerTest { @Test def neg_badAuxConstr = compileFile(negDir, "badAuxConstr", xerrors = 2) @Test def neg_typetest = compileFile(negDir, "typetest", xerrors = 1) @Test def neg_t1569_failedAvoid = compileFile(negDir, "t1569-failedAvoid", xerrors = 1) + @Test def neg_cycles = compileFile(negDir, "cycles", xerrors = 6) + @Test def dotc = compileDir(dotcDir + "tools/dotc", twice)(allowDeepSubtypes) @Test def dotc_ast = compileDir(dotcDir + "tools/dotc/ast", twice) @Test def dotc_config = compileDir(dotcDir + "tools/dotc/config", twice) diff --git a/tests/neg/cycles.scala b/tests/neg/cycles.scala index 4eaec125f4cf..dbcbe1efbdb6 100644 --- a/tests/neg/cycles.scala +++ b/tests/neg/cycles.scala @@ -2,3 +2,28 @@ class Foo[T <: U, U <: T] class Bar[T >: T] +class A { + val x: T = ??? + type T <: x.type +} + +class B { + type T <: x.type + val x: T = ??? +} + +class C { + val x: D#T = ??? + class D { + type T <: x.type + val z: x.type = ??? + } +} + +class E { + class F { + type T <: x.type + val z: x.type = ??? + } + val x: F#T = ??? +}