From addd4a645c0b3adb898c74cb9b1197bb04597467 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 24 Oct 2013 17:45:14 +0200 Subject: Flipping the logic to determine type leaks --- src/dotty/tools/dotc/ast/CheckTrees.scala | 2 +- tests/neg/blockescapesNeg.scala | 5 +++++ tests/pos/blockescapes.scala | 11 +++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 tests/neg/blockescapesNeg.scala create mode 100644 tests/pos/blockescapes.scala diff --git a/src/dotty/tools/dotc/ast/CheckTrees.scala b/src/dotty/tools/dotc/ast/CheckTrees.scala index b99548162..290d18b0c 100644 --- a/src/dotty/tools/dotc/ast/CheckTrees.scala +++ b/src/dotty/tools/dotc/ast/CheckTrees.scala @@ -31,7 +31,7 @@ object CheckTrees { } def leakingTypes(tp: Type): Set[NamedType] = tp namedPartsWith (tp => isLocal(tp.symbol)) - def typeLeaks(tp: Type): Boolean = leakingTypes(tp).isEmpty + def typeLeaks(tp: Type): Boolean = leakingTypes(tp).nonEmpty def classLeaks(sym: ClassSymbol): Boolean = (sym.info.parents exists typeLeaks) || (sym.decls.toList exists (t => typeLeaks(t.info))) diff --git a/tests/neg/blockescapesNeg.scala b/tests/neg/blockescapesNeg.scala new file mode 100644 index 000000000..028ef5162 --- /dev/null +++ b/tests/neg/blockescapesNeg.scala @@ -0,0 +1,5 @@ +object blockescapesNeg { + def m0 = { object Foo { class Bar } ; new Foo.Bar } + class A[T] + def m1 = { val x = 1; new A[x.type]} +} \ No newline at end of file diff --git a/tests/pos/blockescapes.scala b/tests/pos/blockescapes.scala new file mode 100644 index 000000000..35d40974b --- /dev/null +++ b/tests/pos/blockescapes.scala @@ -0,0 +1,11 @@ +object blockescapes { + + { val x = 0; () } + val x0 = { class Foo; new Foo } + val x1 = {} + val x2 = { val z = 0 } + val m1 = { val x = 2; x } + + trait T + def m0: T = { object Foo { class Bar extends T } ; new Foo.Bar } +} \ No newline at end of file -- cgit v1.2.3