File tree 2 files changed +25
-33
lines changed
compiler/src/dotty/tools/dotc 2 files changed +25
-33
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 @@ -12,7 +12,6 @@ import Decorators._
12
12
import ast .Trees ._
13
13
import MegaPhase ._
14
14
import java .io .File .separatorChar
15
- import util .{ NoSource , SourceFile }
16
15
17
16
import ValueClasses ._
18
17
@@ -85,29 +84,10 @@ class ExpandPrivate extends MiniPhase with IdentityDenotTransformer { thisPhase
85
84
(j < 0 || p1(j) == separatorChar)
86
85
}
87
86
88
- def findSource (sym : Symbol ): SourceFile = {
89
- def valid (src : SourceFile ): Boolean = src.exists && src.file.extension != " class"
90
-
91
- if (sym eq NoSymbol ) NoSource
92
- else {
93
- val dTree = sym.defTree
94
- if (valid(dTree.source)) dTree.source
95
- else {
96
- val oSrc = findSource(sym.owner)
97
- if (oSrc.exists) oSrc
98
- else if (valid(sym.source))
99
- sym.source
100
- else NoSource
101
- }
102
- }
103
- }
104
-
105
- val dSrc = findSource(d.symbol)
106
- val cSrc = findSource(ctx.owner)
107
-
108
- assert(dSrc.exists && cSrc.exists && isSimilar(dSrc.path, cSrc.path),
109
- s " private ${d.symbol.showLocated} in ${dSrc} accessed from ${ctx.owner.showLocated} in ${cSrc}" )
110
-
87
+ assert(d.symbol.source.exists &&
88
+ ctx.owner.source.exists &&
89
+ isSimilar(d.symbol.source.path, ctx.owner.source.path),
90
+ s " private ${d.symbol.showLocated} in ${d.symbol.source} accessed from ${ctx.owner.showLocated} in ${ctx.owner.source}" )
111
91
d.ensureNotPrivate.installAfter(thisPhase)
112
92
}
113
93
You can’t perform that action at this time.
0 commit comments