Skip to content

Commit 6324a75

Browse files
committed
Add diagnostic why a symbol is stale.
1 parent f3ba2dc commit 6324a75

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/dotty/tools/dotc/core/Denotations.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,10 @@ object Denotations {
590590
} while (d ne denot)
591591
this
592592
case _ =>
593-
if (coveredInterval.containsPhaseId(ctx.phaseId)) staleSymbolError
593+
if (coveredInterval.containsPhaseId(ctx.phaseId)) {
594+
if (ctx.settings.debug.value) ctx.traceInvalid(this)
595+
staleSymbolError
596+
}
594597
else NoDenotation
595598
}
596599

src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,37 @@ trait SymDenotations { this: Context =>
5757
} catch {
5858
case ex: StaleSymbol => false
5959
}
60+
61+
/** Explain why symbol is invalid; used for debugging only */
62+
def traceInvalid(denot: Denotation): Boolean = {
63+
def show(d: Denotation) = s"$d#${d.symbol.id}"
64+
def explain(msg: String) = {
65+
println(s"${show(denot)} is invalid at ${this.period} because $msg")
66+
false
67+
}
68+
denot match {
69+
case denot: SymDenotation =>
70+
def explainSym(msg: String) = explain(s"$msg\n defined = ${denot.definedPeriodsString}")
71+
if (denot.is(ValidForever) || denot.isRefinementClass) true
72+
else {
73+
implicit val ctx: Context = this
74+
val initial = denot.initial
75+
if ((initial ne denot) || ctx.phaseId != initial.validFor.firstPhaseId) {
76+
ctx.withPhase(initial.validFor.firstPhaseId).traceInvalid(initial.asSymDenotation)
77+
} else try {
78+
val owner = denot.owner.denot
79+
if (!traceInvalid(owner)) explainSym("owner is invalid")
80+
else if (!owner.isClass || owner.isRefinementClass || denot.isSelfSym) true
81+
else if (owner.unforcedDecls.lookupAll(denot.name) contains denot.symbol) true
82+
else explainSym(s"decls of ${show(owner)} are ${owner.unforcedDecls.lookupAll(denot.name).toList}, do not contain ${denot.symbol}")
83+
} catch {
84+
case ex: StaleSymbol => explainSym(s"$ex was thrown")
85+
}
86+
}
87+
case _ =>
88+
explain("denotation is not a SymDenotation")
6089
}
90+
}
6191
}
6292

6393
object SymDenotations {

0 commit comments

Comments
 (0)