Skip to content

Fix #4342: Handle Scala2 method calls with an outer param #5801

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,20 @@ object ExplicitOuter {
private def newOuterAccessors(cls: ClassSymbol)(implicit ctx: Context) =
newOuterAccessor(cls, cls) :: (if (cls is Trait) Nil else newOuterParamAccessor(cls) :: Nil)

/** Scala 2.x and Dotty don't always agree on what should be the type of the outer parameter,
* so we replicate the old behavior when passing arguments to methods coming from Scala 2.x.
*/
private def outerClass(cls: ClassSymbol)(implicit ctx: Context): Symbol = {
val encl = cls.owner.enclosingClass
if (cls.is(Scala2x))
encl.asClass.classInfo.selfInfo match {
case tp: TypeRef => tp.classSymbol
case self: Symbol => self
case _ => encl
}
else encl
}

/** A new outer accessor or param accessor.
* @param owner The class where the outer accessor is located
* @param cls The class relative to which the outer is computed (can be a base class of owner)
Expand All @@ -155,7 +169,7 @@ object ExplicitOuter {
*/
private def newOuterSym(owner: ClassSymbol, cls: ClassSymbol, name: TermName, flags: FlagSet)(implicit ctx: Context) = {
val outerThis = owner.owner.enclosingClass.thisType
val outerCls = cls.owner.enclosingClass
val outerCls = outerClass(cls)
val target =
if (owner == cls)
outerCls.appliedRef
Expand Down Expand Up @@ -340,7 +354,7 @@ object ExplicitOuter {
if (hasOuterParam(cls)) {
val mt @ MethodTpe(pnames, ptypes, restpe) = tp
mt.derivedLambdaType(
nme.OUTER :: pnames, cls.owner.enclosingClass.typeRef :: ptypes, restpe)
nme.OUTER :: pnames, outerClass(cls).typeRef :: ptypes, restpe)
} else tp

/** If function in an apply node is a constructor that needs to be passed an
Expand Down