Skip to content

Commit 51db1b5

Browse files
authored
Merge pull request #10448 from michelou/scala3-windows
fixed relativePath on Windows
2 parents 3cdf0fd + d97a9d0 commit 51db1b5

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)