@@ -12,7 +12,7 @@ import Decorators._
1212import ast .Trees ._
1313import MegaPhase ._
1414import java .io .File .separatorChar
15- import util .SourceFile
15+ import util .{ NoSource , SourceFile }
1616
1717import ValueClasses ._
1818
@@ -85,13 +85,29 @@ class ExpandPrivate extends MiniPhase with IdentityDenotTransformer { thisPhase
8585 (j < 0 || p1(j) == separatorChar)
8686 }
8787
88- lazy val dPath = d.symbol.source.path
88+ def findSource (sym : Symbol ): SourceFile = {
89+ def valid (src : SourceFile ): Boolean = src.exists && src.file.extension != " class"
90+
91+ if (sym eq NoSymbol ) NoSource
92+ else {
93+ val dTree = sym.defTree
94+ if (valid(dTree.source)) dTree.source
95+ else {
96+ val oSrc = findSource(sym.owner)
97+ if (oSrc.exists) oSrc
98+ else if (valid(sym.source))
99+ sym.source
100+ else NoSource
101+ }
102+ }
103+ }
104+
105+ val dSrc = findSource(d.symbol)
106+ val cSrc = findSource(ctx.owner)
89107
90- def check ( src : SourceFile ) : Boolean =
91- src.exists && isSimilar(dPath, src.path )
108+ assert(dSrc.exists && cSrc.exists && isSimilar(dSrc.path, cSrc.path),
109+ s " private ${d.symbol.showLocated} in ${dSrc} accessed from ${ctx.owner.showLocated} in ${cSrc} " )
92110
93- assert(d.symbol.source.exists && (check(ctx.owner.source) || check(ctx.compilationUnit.source)),
94- s " private ${d.symbol.showLocated} in ${d.symbol.source} accessed from ${ctx.owner.showLocated} in ${ctx.owner.source}" )
95111 d.ensureNotPrivate.installAfter(thisPhase)
96112 }
97113
0 commit comments