Skip to content

Commit 4c5c00c

Browse files
committed
Handle usage of dirPathTrailingSlash in DirectoryPath
`dirPathTrailingSlash` is used both in `DirectoryPath` and `ZipArchiveFileLookup`, the former is platform-depndent, while the latter always uses `/` as separator. Previously, the code works by accident: `new JFile(dir, path)` and `dir.resolve(path)` are able to handle `path = "java/lang"` on windows.
1 parent 3ece9d5 commit 4c5c00c

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

compiler/src/dotty/tools/dotc/classpath/ClassPath.scala

+8-1
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,15 @@ trait SourceFileEntry extends ClassRepresentation {
2323
}
2424

2525
case class PackageName(dottedString: String) {
26+
val dirPathTrailingSlashJar: String = FileUtils.dirPathInJar(dottedString) + "/"
27+
28+
val dirPathTrailingSlash: String =
29+
if (java.io.File.separatorChar == '/')
30+
dirPathTrailingSlashJar
31+
else
32+
FileUtils.dirPath(dottedString) + java.io.File.separator
33+
2634
def isRoot: Boolean = dottedString.isEmpty
27-
val dirPathTrailingSlash: String = FileUtils.dirPathInArchive(dottedString) + "/"
2835

2936
def entryName(entry: String): String = {
3037
if (isRoot) entry else {

compiler/src/dotty/tools/dotc/classpath/FileUtils.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ object FileUtils {
4444

4545
def dirPath(forPackage: String): String = forPackage.replace('.', JFile.separatorChar)
4646

47-
def dirPathInArchive(forPackage: String): String = forPackage.replace('.', '/')
47+
def dirPathInJar(forPackage: String): String = forPackage.replace('.', '/')
4848

4949
def endsClass(fileName: String): Boolean =
5050
fileName.length > 6 && fileName.substring(fileName.length - 6) == ".class"

compiler/src/dotty/tools/dotc/classpath/ZipArchiveFileLookup.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ trait ZipArchiveFileLookup[FileEntryType <: ClassRepresentation] extends Efficie
6262
}
6363

6464
private def findDirEntry(pkg: PackageName): Option[archive.DirEntry] =
65-
archive.allDirs.get(pkg.dirPathTrailingSlash)
65+
archive.allDirs.get(pkg.dirPathTrailingSlashJar)
6666

6767
protected def createFileEntry(file: FileZipArchive#Entry): FileEntryType
6868
protected def isRequiredFileType(file: AbstractFile): Boolean

0 commit comments

Comments
 (0)