Skip to content

Commit 58f9665

Browse files
committed
Relativize path in SourceFile annotation
1 parent 0ad43b7 commit 58f9665

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,14 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
335335
&& ctx.compilationUnit.source.exists
336336
&& sym != defn.SourceFileAnnot
337337
then
338-
sym.addAnnotation(Annotation.makeSourceFile(ctx.compilationUnit.source.file.path))
338+
val jpath = ctx.compilationUnit.source.file.jpath.normalize
339+
val sourceroot =
340+
java.nio.file.Paths.get(ctx.settings.sourceroot.value)
341+
.toAbsolutePath
342+
.normalize
343+
val relativePath =
344+
if jpath.isAbsolute then sourceroot.relativize(jpath) else jpath
345+
sym.addAnnotation(Annotation.makeSourceFile(relativePath.toString))
339346
else (tree.rhs, sym.info) match
340347
case (rhs: LambdaTypeTree, bounds: TypeBounds) =>
341348
VarianceChecker.checkLambda(rhs, bounds)

0 commit comments

Comments
 (0)