File tree 4 files changed +30
-9
lines changed
compiler/src/dotty/tools/dotc
4 files changed +30
-9
lines changed Original file line number Diff line number Diff line change @@ -626,15 +626,27 @@ object Symbols {
626
626
final def symbol (implicit ev : DontUseSymbolOnSymbol ): Nothing = unsupported(" symbol" )
627
627
type DontUseSymbolOnSymbol
628
628
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
+ }
638
650
639
651
/** A symbol related to `sym` that is defined in source code.
640
652
*
Original file line number Diff line number Diff line change @@ -165,6 +165,7 @@ object Inliner {
165
165
case tree : SeqLiteral => finalize(tree, untpd.SeqLiteral (transform(tree.elems), transform(tree.elemtpt))(curSource))
166
166
case tree : TypeTree => tpd.TypeTree (tree.tpe)(ctx.withSource(curSource)).withSpan(tree.span)
167
167
case tree : Bind => finalize(tree, untpd.Bind (tree.name, transform(tree.body))(curSource))
168
+ case tree : DefTree => super .transform(tree).setDefTree
168
169
case _ => super .transform(tree)
169
170
})
170
171
assert(transformed.isInstanceOf [EmptyTree [_]] || transformed.isInstanceOf [EmptyValDef [_]] || transformed.source == curSource)
Original file line number Diff line number Diff line change
1
+ object Foo {
2
+ inline def foo = new { bar(0 ) }
3
+
4
+ def bar (i : => Int ): Unit = ()
5
+ }
Original file line number Diff line number Diff line change
1
+ object Test {
2
+ val v = Foo .foo
3
+ }
You can’t perform that action at this time.
0 commit comments