Skip to content

Commit 1cf97bf

Browse files
committed
Deal with problem solved by ExplicitSelf in another way
ExplicitSelf was not redundant, after all. The run test i789.scala broke. But we still cannot leave it in has ExplicitSelf turns stable paths into unstable ones, which is a problem. This commit provides another fix to the problem underlying #789.
1 parent 92168ff commit 1cf97bf

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,18 @@ object Erasure extends TypeTestsCasts{
331331
* e.m -> e.[]m if `m` is an array operation other than `clone`.
332332
*/
333333
override def typedSelect(tree: untpd.Select, pt: Type)(implicit ctx: Context): Tree = {
334-
val sym = tree.symbol
334+
val sym = tree.typeOpt match {
335+
case tpe: TermRefWithSignature if tpe.prefix.isInstanceOf[ThisType] =>
336+
// It is surprisingly tricky to find out what symbol this tree had before
337+
// erasure. The problem is caching. if we compute `this.f` after erasure
338+
// we might get the wrong symbol, since `this` does not have an underlying
339+
// self type anymore after erasure. But if we then look for the symbol of
340+
// that same type before erasure, the cache will give us the same, incorrect
341+
// symbol! To sidestep this problem we load the denotation explicitly before
342+
// erasure. Test case is i789.scala.
343+
tpe.loadDenot(ctx.withPhase(ctx.erasurePhase)).symbol
344+
case _ => tree.symbol
345+
}
335346
assert(sym.exists, tree.show)
336347

337348
def select(qual: Tree, sym: Symbol): Tree = {

0 commit comments

Comments
 (0)