Skip to content

Commit f9d27c9

Browse files
committed
Store source files as normal paths, not canonical ones.
This is the same as what Java does for its ClassFile attribute.
1 parent 5debb09 commit f9d27c9

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import TreeTransforms._
1616
import Decorators._
1717
import ast.Trees._
1818
import TreeTransforms._
19+
import java.io.File.separatorChar
1920

2021
/** Make private term members that are accessed from another class
2122
* non-private by resetting the Private flag and expanding their name.
@@ -58,7 +59,20 @@ class ExpandPrivate extends MiniPhaseTransform with IdentityDenotTransformer { t
5859
*/
5960
private def ensurePrivateAccessible(d: SymDenotation)(implicit ctx: Context) =
6061
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),
6276
i"private ${d.symbol.showLocated} in ${d.symbol.sourceFile} accessed from ${ctx.owner.showLocated} in ${ctx.source.file}")
6377
d.ensureNotPrivate.installAfter(thisTransform)
6478
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class Pickler extends Phase {
6868
private def pickleSourcefile(pickler: TastyPickler, source: SourceFile): Unit = {
6969
val buf = new TastyBuffer(10)
7070
pickler.newSection("Sourcefile", buf)
71-
buf.writeNat(pickler.nameBuffer.nameIndex(source.file.canonicalPath).index)
71+
buf.writeNat(pickler.nameBuffer.nameIndex(source.file.path).index)
7272
}
7373

7474
override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = {

0 commit comments

Comments
 (0)