Skip to content

Commit 9daf976

Browse files
committed
Assert that ensureNotPrivate does not break on separate compilation
When ensureNotPrivate changes the status of a formerly private declaration, assert that the reference to the declaration is in the same compilation unit, as otherwise the nehavior would be different under separate compilation.
1 parent d500b1d commit 9daf976

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/dotty/tools/dotc/transform/ExpandPrivate.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,11 @@ class ExpandPrivate extends MiniPhaseTransform with IdentityDenotTransformer { t
5757
* static members of the companion class, we should tighten the condition below.
5858
*/
5959
private def ensurePrivateAccessible(d: SymDenotation)(implicit ctx: Context) =
60-
if (d.is(PrivateTerm) && d.owner != ctx.owner.enclosingClass)
60+
if (d.is(PrivateTerm) && d.owner != ctx.owner.enclosingClass) {
61+
assert(d.symbol.sourceFile == ctx.source.file,
62+
i"private ${d.symbol.showLocated} in ${d.symbol.sourceFile} accessed from ${ctx.owner.showLocated} in ${ctx.source.file}")
6163
d.ensureNotPrivate.installAfter(thisTransform)
64+
}
6265

6366
override def transformIdent(tree: Ident)(implicit ctx: Context, info: TransformerInfo) = {
6467
ensurePrivateAccessible(tree.symbol)

0 commit comments

Comments
 (0)