Skip to content

Commit 4e33a41

Browse files
committed
Scrutinize selections in TreeChecker
Makes sure the symbol in the tree can be approximately reconstructed by calling member on the qualifier type. Approximately means: The two symbols might be different but one still overrides the other.
1 parent f683622 commit 4e33a41

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/dotty/tools/dotc/transform/TreeChecker.scala

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,7 @@ class TreeChecker extends Phase with SymTransformer {
133133
catch {
134134
case NonFatal(ex) => //TODO CHECK. Check that we are bootstrapped
135135
implicit val ctx: Context = checkingCtx
136-
ctx.echo(i"*** error while checking ${ctx.compilationUnit} after phase ${checkingCtx.phase.prev} ***")
137-
ctx.echo(ex.toString)
138-
ctx.echo(ex.getStackTrace.take(30).deep.mkString("\n"))
139-
ctx.echo("<<<")
136+
println(i"*** error while checking ${ctx.compilationUnit} after phase ${checkingCtx.phase.prev} ***")
140137
throw ex
141138
}
142139
}
@@ -332,8 +329,30 @@ class TreeChecker extends Phase with SymTransformer {
332329
checkNotRepeated(super.typedIdent(tree, pt))
333330
}
334331

332+
/** Makes sure the symbol in the tree can be approximately reconstructed by
333+
* calling `member` on the qualifier type.
334+
* Approximately means: The two symbols might be different but one still overrides the other.
335+
*/
335336
override def typedSelect(tree: untpd.Select, pt: Type)(implicit ctx: Context): Tree = {
336337
assert(tree.isTerm || !ctx.isAfterTyper, tree.show + " at " + ctx.phase)
338+
val tpe = tree.typeOpt
339+
val sym = tree.symbol
340+
if (!tpe.isInstanceOf[WithFixedSym] && sym.exists && !sym.is(Private)) {
341+
val qualTpe = tree.qualifier.typeOpt
342+
val member =
343+
if (sym.is(Private)) qualTpe.member(tree.name)
344+
else qualTpe.nonPrivateMember(tree.name)
345+
val memberSyms = member.alternatives.map(_.symbol)
346+
assert(memberSyms.exists(mbr =>
347+
sym == mbr ||
348+
sym.overriddenSymbol(mbr.owner.asClass) == mbr ||
349+
mbr.overriddenSymbol(sym.owner.asClass) == sym),
350+
ex"""symbols differ for $tree
351+
|was : $sym
352+
|alternatives by type: $memberSyms%, % of types ${memberSyms.map(_.info)}%, %
353+
|qualifier type : ${tree.qualifier.typeOpt}
354+
|tree type : ${tree.typeOpt} of class ${tree.typeOpt.getClass}""")
355+
}
337356
checkNotRepeated(super.typedSelect(tree, pt))
338357
}
339358

0 commit comments

Comments
 (0)