@@ -290,8 +290,20 @@ class Inliner(call: tpd.Tree, rhs: tpd.Tree)(implicit ctx: Context) {
290
290
*/
291
291
private val paramProxy = new mutable.HashMap [Type , Type ]
292
292
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 ]
295
307
296
308
/** A buffer for bindings that define proxies for actual arguments */
297
309
val bindingsBuf = new mutable.ListBuffer [ValOrDefDef ]
@@ -349,13 +361,13 @@ class Inliner(call: tpd.Tree, rhs: tpd.Tree)(implicit ctx: Context) {
349
361
private def registerType (tpe : Type ): Unit = tpe match {
350
362
case tpe : ThisType
351
363
if ! ctx.owner.isContainedIn(tpe.cls) && ! tpe.cls.is(Package ) &&
352
- ! thisProxy.contains(tpe) =>
364
+ ! thisProxy.contains(tpe.cls ) =>
353
365
if (tpe.cls.isStaticOwner)
354
- thisProxy(tpe) = tpe.cls.sourceModule.termRef
366
+ thisProxy(tpe.cls ) = tpe.cls.sourceModule.termRef
355
367
else {
356
368
val proxyName = s " ${tpe.cls.name}_this " .toTermName
357
369
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
359
371
registerType(meth.owner.thisType) // make sure we have a base from which to outer-select
360
372
}
361
373
case tpe : NamedType
@@ -408,7 +420,7 @@ class Inliner(call: tpd.Tree, rhs: tpd.Tree)(implicit ctx: Context) {
408
420
// and parameters to type references of their arguments or proxies.
409
421
val typeMap = new TypeMap {
410
422
def apply (t : Type ) = t match {
411
- case t : ThisType => thisProxy.getOrElse(t, t)
423
+ case t : ThisType => thisProxy.getOrElse(t.cls , t)
412
424
case t : TypeRef => paramProxy.getOrElse(t, mapOver(t))
413
425
case t : SingletonType => paramProxy.getOrElse(t, mapOver(t))
414
426
case t => mapOver(t)
@@ -420,9 +432,13 @@ class Inliner(call: tpd.Tree, rhs: tpd.Tree)(implicit ctx: Context) {
420
432
def treeMap (tree : Tree ) = {
421
433
tree match {
422
434
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
426
442
}
427
443
case _ : Ident =>
428
444
paramProxy.get(tree.tpe) match {
0 commit comments