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