File tree Expand file tree Collapse file tree 2 files changed +25
-33
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 2 files changed +25
-33
lines changed Original file line number Diff line number Diff 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 *
Original file line number Diff line number Diff line change @@ -12,7 +12,6 @@ import Decorators._
1212import ast .Trees ._
1313import MegaPhase ._
1414import java .io .File .separatorChar
15- import util .{ NoSource , SourceFile }
1615
1716import ValueClasses ._
1817
@@ -85,29 +84,10 @@ class ExpandPrivate extends MiniPhase with IdentityDenotTransformer { thisPhase
8584 (j < 0 || p1(j) == separatorChar)
8685 }
8786
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}" )
11191 d.ensureNotPrivate.installAfter(thisPhase)
11292 }
11393
You can’t perform that action at this time.
0 commit comments