Skip to content

Commit d97a9d0

Browse files
committed
fixed relativePath on Windows
1 parent 4265f08 commit d97a9d0

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,12 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
343343
val jpath = file.jpath
344344
val relativePath =
345345
if jpath eq null then file.path // repl and other custom tests use abstract files with no path
346-
else if jpath.isAbsolute then sourcerootPath.relativize(jpath.normalize).toString
346+
else if jpath.isAbsolute then
347+
val cunitPath = jpath.normalize
348+
// On Windows we can only relativize paths if root component matches
349+
// (see implementation of sun.nio.fs.WindowsPath#relativize)
350+
try sourcerootPath.relativize(cunitPath).toString
351+
catch case _: IllegalArgumentException => cunitPath.toString
347352
else jpath.normalize.toString
348353
sym.addAnnotation(Annotation.makeSourceFile(relativePath))
349354
else (tree.rhs, sym.info) match

0 commit comments

Comments
 (0)