Skip to content

Commit 5704089

Browse files
committed
Fix ExplicitSelf phase
After inlining we got a Ycheck error of the form: found : `this.asInstanceOf[SelfType].C` expected: `this.C` The fact that it was related inlining was coincidental I think. We fix the problem by expanding to this.asInstanceOf[SelfType & this.type].C instead.
1 parent 7941bc0 commit 5704089

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ import Flags._
1616
* where `C` is a class with explicit self type and `C` is not a
1717
* subclass of the owner of `m` to
1818
*
19-
* C.this.asInstanceOf[S].m
19+
* C.this.asInstanceOf[S & C.this.type].m
2020
*
2121
* where `S` is the self type of `C`.
22+
* See run/i789.scala for a test case why this is needed.
2223
*/
2324
class ExplicitSelf extends MiniPhaseTransform { thisTransform =>
2425
import ast.tpd._
@@ -30,7 +31,7 @@ class ExplicitSelf extends MiniPhaseTransform { thisTransform =>
3031
val cls = thiz.symbol.asClass
3132
val cinfo = cls.classInfo
3233
if (cinfo.givenSelfType.exists && !cls.derivesFrom(tree.symbol.owner))
33-
cpy.Select(tree)(thiz.asInstance(cinfo.selfType), name)
34+
cpy.Select(tree)(thiz.asInstance(AndType(cinfo.selfType, thiz.tpe)), name)
3435
else tree
3536
case _ => tree
3637
}

0 commit comments

Comments
 (0)