Skip to content

Commit

Permalink
Prepare for @SourceFile removal
Browse files Browse the repository at this point in the history
The only missing step is in the TODO added in this commit.
  • Loading branch information
nicolasstucki committed Nov 30, 2023
1 parent c755be1 commit 9ceef59
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
3 changes: 0 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,6 @@ object Annotations {
}
else None
}

def makeSourceFile(path: String, span: Span)(using Context): Annotation =
apply(defn.SourceFileAnnot, Literal(Constant(path)), span)
}

@sharable val EmptyAnnotation = Annotation(EmptyTree)
Expand Down
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/PostTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,13 @@ class PostTyper extends MacroTransform with InfoTransformer { thisPhase =>
if illegalRefs.nonEmpty then
report.error(
em"The type of a class parent cannot refer to constructor parameters, but ${parent.tpe} refers to ${illegalRefs.map(_.name.show).mkString(",")}", parent.srcPos)
// Add SourceFile annotation to top-level classes
if sym.owner.is(Package) then
// Add SourceFile annotation to top-level classes
// TODO remove this annotation once the reference compiler uses the TASTy source file attribute.
if ctx.compilationUnit.source.exists && sym != defn.SourceFileAnnot then
val reference = ctx.settings.sourceroot.value
val relativePath = util.SourceFile.relativePath(ctx.compilationUnit.source, reference)
sym.addAnnotation(Annotation.makeSourceFile(relativePath, tree.span))
sym.addAnnotation(Annotation(defn.SourceFileAnnot, Literal(Constants.Constant(relativePath)), tree.span))
else
if !sym.is(Param) && !sym.owner.isOneOf(AbstractOrTrait) then
Checking.checkGoodBounds(tree.symbol)
Expand Down

0 comments on commit 9ceef59

Please sign in to comment.