@@ -140,6 +140,20 @@ object ExplicitOuter {
140
140
private def newOuterAccessors (cls : ClassSymbol )(implicit ctx : Context ) =
141
141
newOuterAccessor(cls, cls) :: (if (cls is Trait ) Nil else newOuterParamAccessor(cls) :: Nil )
142
142
143
+ /** Scala 2.x and Dotty don't always agree on what should be the type of the outer parameter,
144
+ * so we replicate the old behavior when passing arguments to methods coming from Scala 2.x.
145
+ */
146
+ private def outerClass (cls : ClassSymbol )(implicit ctx : Context ): Symbol = {
147
+ val encl = cls.owner.enclosingClass
148
+ if (cls.is(Scala2x ))
149
+ encl.asClass.classInfo.selfInfo match {
150
+ case tp : TypeRef => tp.classSymbol
151
+ case self : Symbol => self
152
+ case _ => encl
153
+ }
154
+ else encl
155
+ }
156
+
143
157
/** A new outer accessor or param accessor.
144
158
* @param owner The class where the outer accessor is located
145
159
* @param cls The class relative to which the outer is computed (can be a base class of owner)
@@ -155,7 +169,7 @@ object ExplicitOuter {
155
169
*/
156
170
private def newOuterSym (owner : ClassSymbol , cls : ClassSymbol , name : TermName , flags : FlagSet )(implicit ctx : Context ) = {
157
171
val outerThis = owner.owner.enclosingClass.thisType
158
- val outerCls = cls.owner.enclosingClass
172
+ val outerCls = outerClass( cls)
159
173
val target =
160
174
if (owner == cls)
161
175
outerCls.appliedRef
@@ -340,7 +354,7 @@ object ExplicitOuter {
340
354
if (hasOuterParam(cls)) {
341
355
val mt @ MethodTpe (pnames, ptypes, restpe) = tp
342
356
mt.derivedLambdaType(
343
- nme.OUTER :: pnames, cls.owner.enclosingClass .typeRef :: ptypes, restpe)
357
+ nme.OUTER :: pnames, outerClass( cls) .typeRef :: ptypes, restpe)
344
358
} else tp
345
359
346
360
/** If function in an apply node is a constructor that needs to be passed an
0 commit comments