From 6ae376a4544cbf93b94dc0a6ba4a78224e0477df Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Tue, 4 Apr 2017 19:17:42 +0200 Subject: checkNoPrivateLeaks: Do not allow types to refer to leaky aliases `checkNoPrivateLeaks` can force a lot of things, this lead to hard-to-reproduce issues in unpickling because we called `checkNoPrivateLeaks` on the type parameters of a class before anything in the class was indexed. We fix this by making sure that `checkNoPrivateLeaks` never transforms type symbols, only term symbols, therefore we can unpickle type parameters without forcing too many things. tests/neg/leak-type.scala illustrates the new restriction that this necessitates. --- tests/neg/leak-type.scala | 13 +++++++++++++ tests/pos/i1130.scala | 4 +++- tests/pos/leak-inferred.scala | 12 ++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/neg/leak-type.scala create mode 100644 tests/pos/leak-inferred.scala (limited to 'tests') diff --git a/tests/neg/leak-type.scala b/tests/neg/leak-type.scala new file mode 100644 index 000000000..30ecab70b --- /dev/null +++ b/tests/neg/leak-type.scala @@ -0,0 +1,13 @@ +trait A { + private type Foo = Int + + + class Inner[T <: Foo] { // error: non-private type T refers to private type Foo in its type signature + def get: T = ??? + } +} +class B extends A { + def foo(x: Inner[_]): Unit = { + val a = x.get // error: cannot resolve reference to type B(B.this).Foo + } +} diff --git a/tests/pos/i1130.scala b/tests/pos/i1130.scala index 8d71de5e8..c28eaa169 100644 --- a/tests/pos/i1130.scala +++ b/tests/pos/i1130.scala @@ -3,4 +3,6 @@ trait A { def foo: Foo = 1 } -class B extends A +class B extends A { + foo +} diff --git a/tests/pos/leak-inferred.scala b/tests/pos/leak-inferred.scala new file mode 100644 index 000000000..5d8a7e3bc --- /dev/null +++ b/tests/pos/leak-inferred.scala @@ -0,0 +1,12 @@ +class A { + private val x = List(1,2) + + val elem = x.head +} + +class B extends A { + val a: Int = elem + // Without `checkNoPrivateLeaks`, we get: + // found: B.this.x.scala$collection$immutable$List$$A(B.this.elem) + // required: Int +} -- cgit v1.2.3