Skip to content

Commit 28cf0cb

Browse files
authored
Merge pull request #6757 from milessabin/topic/inline-refinement-by-name
Symbol#source correct for all phases
2 parents 355bcc0 + cf44e91 commit 28cf0cb

File tree

4 files changed

+30
-9
lines changed

4 files changed

+30
-9
lines changed

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

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -626,15 +626,27 @@ object Symbols {
626626
final def symbol(implicit ev: DontUseSymbolOnSymbol): Nothing = unsupported("symbol")
627627
type DontUseSymbolOnSymbol
628628

629-
final def source(implicit ctx: Context): SourceFile =
630-
if (!defTree.isEmpty && !ctx.erasedTypes) defTree.source
631-
else this match {
632-
case cls: ClassSymbol => cls.sourceOfClass
633-
case _ =>
634-
if (denot.is(Module)) denot.moduleClass.source
635-
else if (denot.exists) denot.owner.source
636-
else NoSource
637-
}
629+
final def source(implicit ctx: Context): SourceFile = {
630+
def valid(src: SourceFile): SourceFile =
631+
if (src.exists && src.file.extension != "class") src
632+
else NoSource
633+
634+
if (!denot.exists) NoSource
635+
else
636+
valid(defTree.source) match {
637+
case NoSource =>
638+
valid(denot.owner.source) match {
639+
case NoSource =>
640+
this match {
641+
case cls: ClassSymbol => valid(cls.sourceOfClass)
642+
case _ if denot.is(Module) => valid(denot.moduleClass.source)
643+
case _ => NoSource
644+
}
645+
case src => src
646+
}
647+
case src => src
648+
}
649+
}
638650

639651
/** A symbol related to `sym` that is defined in source code.
640652
*

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ object Inliner {
165165
case tree: SeqLiteral => finalize(tree, untpd.SeqLiteral(transform(tree.elems), transform(tree.elemtpt))(curSource))
166166
case tree: TypeTree => tpd.TypeTree(tree.tpe)(ctx.withSource(curSource)).withSpan(tree.span)
167167
case tree: Bind => finalize(tree, untpd.Bind(tree.name, transform(tree.body))(curSource))
168+
case tree: DefTree => super.transform(tree).setDefTree
168169
case _ => super.transform(tree)
169170
})
170171
assert(transformed.isInstanceOf[EmptyTree[_]] || transformed.isInstanceOf[EmptyValDef[_]] || transformed.source == curSource)

tests/pos/inline-joint/defn.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object Foo {
2+
inline def foo = new { bar(0) }
3+
4+
def bar(i: => Int): Unit = ()
5+
}

tests/pos/inline-joint/use.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Test {
2+
val v = Foo.foo
3+
}

0 commit comments

Comments
 (0)