Skip to content

Commit 7349d7f

Browse files
Merge pull request #9188 from dotty-staging/fix-#9186
Fix #9186: Only warn when the path cannot be relativized
2 parents a8c27ee + 62f8e7c commit 7349d7f

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

compiler/src/dotty/tools/dotc/core/tasty/PositionPickler.scala

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,18 @@ class PositionPickler(pickler: TastyPickler, addrOfTree: untpd.Tree => Addr) {
4848
def pickleSource(source: SourceFile): Unit = {
4949
buf.writeInt(SOURCE)
5050
val pathName = source.path
51-
val path = java.nio.file.Paths.get(pathName.toString).toAbsolutePath().normalize()
52-
val cwd = java.nio.file.Paths.get("").toAbsolutePath().normalize()
53-
val relativePath = (cwd.relativize(path))
54-
assert(!relativePath.isAbsolute)
55-
buf.writeInt(pickler.nameBuffer.nameIndex(relativePath.toString.toTermName).index)
51+
val pickledPath =
52+
val originalPath = java.nio.file.Paths.get(pathName.toString).normalize()
53+
if originalPath.isAbsolute then
54+
val path = originalPath.toAbsolutePath().normalize()
55+
val cwd = java.nio.file.Paths.get("").toAbsolutePath().normalize()
56+
try cwd.relativize(path)
57+
catch case _: IllegalArgumentException =>
58+
ctx.warning("Could not relativize path for pickling: " + originalPath)
59+
originalPath
60+
else
61+
originalPath
62+
buf.writeInt(pickler.nameBuffer.nameIndex(pickledPath.toString.toTermName).index)
5663
}
5764

5865
/** True if x's position shouldn't be reconstructed automatically from its initial span

0 commit comments

Comments
 (0)