File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
compiler/src/dotty/tools/dotc/transform Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -335,7 +335,17 @@ 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+ def sourcerootPath =
339+ java.nio.file.Paths .get(ctx.settings.sourceroot.value)
340+ .toAbsolutePath
341+ .normalize
342+ val file = ctx.compilationUnit.source.file
343+ val jpath = file.jpath
344+ val relativePath =
345+ 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
347+ else jpath.normalize.toString
348+ sym.addAnnotation(Annotation .makeSourceFile(relativePath))
339349 else (tree.rhs, sym.info) match
340350 case (rhs : LambdaTypeTree , bounds : TypeBounds ) =>
341351 VarianceChecker .checkLambda(rhs, bounds)
Original file line number Diff line number Diff line change @@ -33,6 +33,11 @@ clear_out "$OUT"
3333" $SBT " " ;scalac -d $OUT /out.jar $SOURCE ; scalac -decompile -color:never $OUT /out.jar" > " $tmp "
3434grep -qe " def main(args: scala.Array\[scala.Predef.String\]): scala.Unit =" " $tmp "
3535
36+ echo " testing that paths SourceFile annotations are relativized"
37+ clear_out " $OUT "
38+ " $SBT " " ;scalac -d $OUT /out.jar $( pwd) /$SOURCE ; scalac -decompile -color:never $OUT /out.jar" > " $tmp "
39+ grep -qe " SourceFile(\" $SOURCE \" )" " $tmp "
40+
3641echo " testing sbt scalac with suspension"
3742clear_out " $OUT "
3843" $SBT " " scala3-compiler-bootstrapped/scalac -d $OUT tests/pos-macros/macros-in-same-project-1/Bar.scala tests/pos-macros/macros-in-same-project-1/Foo.scala" > " $tmp "
You can’t perform that action at this time.
0 commit comments