@@ -95,7 +95,7 @@ class ExplicitOuter extends MiniPhaseTransform with InfoTransformer { thisTransf
95
95
if (needsOuterIfReferenced(parentTrait)) {
96
96
val parentTp = cls.denot.thisType.baseTypeRef(parentTrait)
97
97
val outerAccImpl = newOuterAccessor(cls, parentTrait).enteredAfter(thisTransformer)
98
- newDefs += DefDef (outerAccImpl, singleton(outerPrefix(parentTp)))
98
+ newDefs += DefDef (outerAccImpl, singleton(fixThis( outerPrefix(parentTp) )))
99
99
}
100
100
}
101
101
@@ -275,6 +275,25 @@ object ExplicitOuter {
275
275
outerPrefix(tpe.underlying)
276
276
}
277
277
278
+ /** It's possible (i1755.scala gives an example) that the type
279
+ * given by outerPrefix contains a This-reference to a module outside
280
+ * the context where that module is defined. This needs to be translated
281
+ * to an access to the module object from the enclosing class or object.
282
+ *
283
+ * This solution is a bit of a hack; it would be better to avoid
284
+ * such references to the This of a module from outside the module
285
+ * in the first place. I was not yet able to find out how such references
286
+ * arise and how to avoid them.
287
+ */
288
+ private def fixThis (tpe : Type )(implicit ctx : Context ): Type = tpe match {
289
+ case tpe : ThisType if tpe.cls.is(Module ) && ! ctx.owner.isContainedIn(tpe.cls) =>
290
+ fixThis(TermRef (tpe.cls.owner.thisType, tpe.cls.sourceModule.asTerm))
291
+ case tpe : TermRef =>
292
+ tpe.derivedSelect(fixThis(tpe.prefix))
293
+ case _ =>
294
+ tpe
295
+ }
296
+
278
297
def outer (implicit ctx : Context ): OuterOps = new OuterOps (ctx)
279
298
280
299
/** The operations in this class
@@ -313,7 +332,7 @@ object ExplicitOuter {
313
332
val cls = fun.symbol.owner.asClass
314
333
def outerArg (receiver : Tree ): Tree = receiver match {
315
334
case New (_) | Super (_, _) =>
316
- singleton(outerPrefix(receiver.tpe))
335
+ singleton(fixThis( outerPrefix(receiver.tpe) ))
317
336
case This (_) =>
318
337
ref(outerParamAccessor(cls)) // will be rewired to outer argument of secondary constructor in phase Constructors
319
338
case TypeApply (Select (r, nme.asInstanceOf_), args) =>
0 commit comments