Skip to content

Commit 43a102f

Browse files
committed
Fix Symbol#sourceFile
defTree should take precedence over associated files. This matters for inlined code.
1 parent 110745e commit 43a102f

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

compiler/src/dotty/tools/dotc/core/Symbols.scala

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -624,21 +624,22 @@ object Symbols {
624624
type DontUseSymbolOnSymbol
625625

626626
/** The source file from which this class was generated, null if not applicable. */
627-
final def sourceFile(implicit ctx: Context): AbstractFile = {
628-
val file = associatedFile
629-
if (file != null && file.extension != "class") file
630-
else if (!defTree.isEmpty) defTree.source.file
627+
final def sourceFile(implicit ctx: Context): AbstractFile =
628+
if (!defTree.isEmpty) defTree.source.file
631629
else {
632-
val topLevelCls = denot.topLevelClass(ctx.withPhaseNoLater(ctx.flattenPhase))
633-
topLevelCls.unforcedAnnotation(defn.SourceFileAnnot) match {
634-
case Some(sourceAnnot) => sourceAnnot.argumentConstant(0) match {
635-
case Some(Constant(path: String)) => AbstractFile.getFile(path)
630+
val file = associatedFile
631+
if (file != null && file.extension != "class") file
632+
else {
633+
val topLevelCls = denot.topLevelClass(ctx.withPhaseNoLater(ctx.flattenPhase))
634+
topLevelCls.unforcedAnnotation(defn.SourceFileAnnot) match {
635+
case Some(sourceAnnot) => sourceAnnot.argumentConstant(0) match {
636+
case Some(Constant(path: String)) => AbstractFile.getFile(path)
637+
case none => null
638+
}
636639
case none => null
637640
}
638-
case none => null
639641
}
640642
}
641-
}
642643

643644
def source(implicit ctx: Context): SourceFile = ctx.getSource(sourceFile)
644645

0 commit comments

Comments
 (0)