Skip to content

Commit 9131a08

Browse files
committed
Ignore virtual source files in Trees and Symbols
If a tree or symbol is created with a virtual source file, use the context's source instead for erro reporting. Without this tweak, replTests fails. It seems the REPL does not follow the assumption that on tree or symbol creation the context always has the right source file (including contents). We should fix that, and then revert this commit.
1 parent 3441e15 commit 9131a08

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ object Trees {
7070

7171
def sourcePos(implicit ctx: Context): SourcePosition = {
7272
val src = source
73-
val srcCtx = ctx.withSource(src)
73+
val srcCtx =
74+
if (src.file.isVirtual) ctx // don't trust virtual files for tree creation - replTest fails otherwise
75+
else ctx.withSource(src)
7476
Decorators.sourcePos(pos)(srcCtx)
7577
}
7678

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,9 @@ object Symbols {
659659
final def sourcePos(implicit ctx: Context): SourcePosition = {
660660
val source = {
661661
val f = sourceFile
662-
if (f == null) ctx.source
662+
if (f == null || f.isVirtual)
663+
// don't trust virtual files for tree creation - replTest fails otherwise
664+
ctx.source
663665
else ctx.getSource(f)
664666
}
665667
SourcePosition(source, pos)

0 commit comments

Comments
 (0)