Skip to content

Commit a2b1e60

Browse files
committed
Make inliner not rely on ambiguous map key
1 parent 7f0637c commit a2b1e60

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,20 @@ class Inliner(call: tpd.Tree, rhs: tpd.Tree)(implicit ctx: Context) {
290290
*/
291291
private val paramProxy = new mutable.HashMap[Type, Type]
292292

293-
/** A map from (direct and outer) this references in `rhs` to references of their proxies */
294-
private val thisProxy = new mutable.HashMap[Type, TermRef]
293+
/** A map from the classes of (direct and outer) this references in `rhs`
294+
* to references of their proxies.
295+
* Note that we can't index by the ThisType itself since there are several
296+
* possible forms to express what is logicaly the same ThisType. E.g.
297+
*
298+
* ThisType(TypeRef(ThisType(p), cls))
299+
*
300+
* vs
301+
*
302+
* ThisType(TypeRef(TermRef(ThisType(<root>), p), cls))
303+
*
304+
* These are different (wrt ==) types but represent logically the same key
305+
*/
306+
private val thisProxy = new mutable.HashMap[ClassSymbol, TermRef]
295307

296308
/** A buffer for bindings that define proxies for actual arguments */
297309
val bindingsBuf = new mutable.ListBuffer[ValOrDefDef]
@@ -349,13 +361,13 @@ class Inliner(call: tpd.Tree, rhs: tpd.Tree)(implicit ctx: Context) {
349361
private def registerType(tpe: Type): Unit = tpe match {
350362
case tpe: ThisType
351363
if !ctx.owner.isContainedIn(tpe.cls) && !tpe.cls.is(Package) &&
352-
!thisProxy.contains(tpe) =>
364+
!thisProxy.contains(tpe.cls) =>
353365
if (tpe.cls.isStaticOwner)
354-
thisProxy(tpe) = tpe.cls.sourceModule.termRef
366+
thisProxy(tpe.cls) = tpe.cls.sourceModule.termRef
355367
else {
356368
val proxyName = s"${tpe.cls.name}_this".toTermName
357369
val proxyType = tpe.asSeenFrom(prefix.tpe, meth.owner)
358-
thisProxy(tpe) = newSym(proxyName, EmptyFlags, proxyType).termRef
370+
thisProxy(tpe.cls) = newSym(proxyName, EmptyFlags, proxyType).termRef
359371
registerType(meth.owner.thisType) // make sure we have a base from which to outer-select
360372
}
361373
case tpe: NamedType
@@ -408,7 +420,7 @@ class Inliner(call: tpd.Tree, rhs: tpd.Tree)(implicit ctx: Context) {
408420
// and parameters to type references of their arguments or proxies.
409421
val typeMap = new TypeMap {
410422
def apply(t: Type) = t match {
411-
case t: ThisType => thisProxy.getOrElse(t, t)
423+
case t: ThisType => thisProxy.getOrElse(t.cls, t)
412424
case t: TypeRef => paramProxy.getOrElse(t, mapOver(t))
413425
case t: SingletonType => paramProxy.getOrElse(t, mapOver(t))
414426
case t => mapOver(t)
@@ -420,9 +432,13 @@ class Inliner(call: tpd.Tree, rhs: tpd.Tree)(implicit ctx: Context) {
420432
def treeMap(tree: Tree) = {
421433
tree match {
422434
case _: This =>
423-
thisProxy.get(tree.tpe) match {
424-
case Some(t) => ref(t).withPos(tree.pos)
425-
case None => tree
435+
tree.tpe match {
436+
case thistpe: ThisType =>
437+
thisProxy.get(thistpe.cls) match {
438+
case Some(t) => ref(t).withPos(tree.pos)
439+
case None => tree
440+
}
441+
case _ => tree
426442
}
427443
case _: Ident =>
428444
paramProxy.get(tree.tpe) match {

0 commit comments

Comments
 (0)