Skip to content

Commit 9fa4153

Browse files
committed
Use defTrees in ExpandPrivate where possible
* In the inliner set defTrees for newly created inlined symbols. * In ensurePrivateAccessible take sources from defTrees where possible.
1 parent 6169318 commit 9fa4153

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

compiler/src/dotty/tools/dotc/transform/ExpandPrivate.scala

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Decorators._
1212
import ast.Trees._
1313
import MegaPhase._
1414
import java.io.File.separatorChar
15-
import util.SourceFile
15+
import util.{ NoSource, SourceFile }
1616

1717
import ValueClasses._
1818

@@ -85,13 +85,29 @@ class ExpandPrivate extends MiniPhase with IdentityDenotTransformer { thisPhase
8585
(j < 0 || p1(j) == separatorChar)
8686
}
8787

88-
lazy val dPath = d.symbol.source.path
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)
89107

90-
def check(src: SourceFile): Boolean =
91-
src.exists && isSimilar(dPath, src.path)
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}")
92110

93-
assert(d.symbol.source.exists && (check(ctx.owner.source) || check(ctx.compilationUnit.source)),
94-
s"private ${d.symbol.showLocated} in ${d.symbol.source} accessed from ${ctx.owner.showLocated} in ${ctx.owner.source}")
95111
d.ensureNotPrivate.installAfter(thisPhase)
96112
}
97113

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)

0 commit comments

Comments
 (0)