Skip to content

Commit a39e662

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

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,11 @@ 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 = java.nio.file.Paths.get(".").toAbsolutePath.normalize
340+
val relativePath =
341+
if jpath.isAbsolute then sourceRoot.relativize(jpath) else jpath
342+
sym.addAnnotation(Annotation.makeSourceFile(relativePath.toString))
339343
else (tree.rhs, sym.info) match
340344
case (rhs: LambdaTypeTree, bounds: TypeBounds) =>
341345
VarianceChecker.checkLambda(rhs, bounds)

0 commit comments

Comments
 (0)