Skip to content

Commit 57da77f

Browse files
committed
Add neg test for checking private leaks
1 parent ed9b664 commit 57da77f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/neg/export-leaks.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Check that exports do not leak private types
2+
object Signature {
3+
4+
private type T
5+
6+
object O1 {
7+
private[Signature] def bar: T = ???
8+
}
9+
export O1._ // error: non-private method bar refers to private type T
10+
11+
object O2 {
12+
private[Signature] val foo: T = ???
13+
}
14+
export O2._ // OK
15+
// The reason this works is that private escape checking only looks at real private members,
16+
// not at private[C] members. So, by itself the expansion of the export
17+
// <stable> def foo: O2.foo.type = O2.foo
18+
// is legal. The underlying type of `O2.foo.type` does violate no-escape rules, but we do not
19+
// check for it. Maybe we should. But then the question comes up whether we should
20+
// also check all possible supertypes of a type for privacy violations. These are more
21+
// general questions that are not related to exports.
22+
}

0 commit comments

Comments
 (0)