File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
src/dotty/tools/dotc/transform Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import TreeTransforms._
16
16
import Decorators ._
17
17
import ast .Trees ._
18
18
import TreeTransforms ._
19
+ import java .io .File .separatorChar
19
20
20
21
/** Make private term members that are accessed from another class
21
22
* non-private by resetting the Private flag and expanding their name.
@@ -58,7 +59,20 @@ class ExpandPrivate extends MiniPhaseTransform with IdentityDenotTransformer { t
58
59
*/
59
60
private def ensurePrivateAccessible (d : SymDenotation )(implicit ctx : Context ) =
60
61
if (d.is(PrivateTerm ) && d.owner != ctx.owner.enclosingClass) {
61
- assert(d.symbol.sourceFile == ctx.source.file,
62
+ // Paths `p1` and `p2` are similar if they have a common suffix that follows
63
+ // possibly different directory paths. That is, their common suffix extends
64
+ // in both cases either to the start of the path or to a file separator character.
65
+ def isSimilar (p1 : String , p2 : String ): Boolean = {
66
+ var i = p1.length - 1
67
+ var j = p2.length - 1
68
+ while (i >= 0 && j >= 0 && p1(i) == p2(j) && p1(i) != separatorChar) {
69
+ i -= 1
70
+ j -= 1
71
+ }
72
+ (i < 0 || p1(i) == separatorChar) &&
73
+ (j < 0 || p1(j) == separatorChar)
74
+ }
75
+ assert(isSimilar(d.symbol.sourceFile.path, ctx.source.file.path),
62
76
i " private ${d.symbol.showLocated} in ${d.symbol.sourceFile} accessed from ${ctx.owner.showLocated} in ${ctx.source.file}" )
63
77
d.ensureNotPrivate.installAfter(thisTransform)
64
78
}
Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ class Pickler extends Phase {
68
68
private def pickleSourcefile (pickler : TastyPickler , source : SourceFile ): Unit = {
69
69
val buf = new TastyBuffer (10 )
70
70
pickler.newSection(" Sourcefile" , buf)
71
- buf.writeNat(pickler.nameBuffer.nameIndex(source.file.canonicalPath ).index)
71
+ buf.writeNat(pickler.nameBuffer.nameIndex(source.file.path ).index)
72
72
}
73
73
74
74
override def runOn (units : List [CompilationUnit ])(implicit ctx : Context ): List [CompilationUnit ] = {
You can’t perform that action at this time.
0 commit comments