Skip to content

Commit 797a938

Browse files
oderskysmarter
authored andcommitted
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 25c0398 commit 797a938

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
}
@@ -331,8 +328,30 @@ class TreeChecker extends Phase with SymTransformer {
331328
checkNotRepeated(super.typedIdent(tree, pt))
332329
}
333330

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

0 commit comments

Comments
 (0)