aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/transform/ExplicitOuter.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-11-03 11:16:20 +0100
committerMartin Odersky <odersky@gmail.com>2014-11-09 19:08:59 +0100
commitd28754110576070ea6f94e626005d149a3470d20 (patch)
treee6ad12f7fff9af5838b503f42b6d4b336e41499c /src/dotty/tools/dotc/transform/ExplicitOuter.scala
parenta2f558146e2d18a6ce1702bb7d48b69f36e38c80 (diff)
downloaddotty-d28754110576070ea6f94e626005d149a3470d20.tar.gz
dotty-d28754110576070ea6f94e626005d149a3470d20.tar.bz2
dotty-d28754110576070ea6f94e626005d149a3470d20.zip
Adaptation of explicitOuter to trait initializers
Trait initializers do not have outer params; need to avoid passing outer args to them. This problem did not manifest itself before because no trait constructor calls were generated before erasure.
Diffstat (limited to 'src/dotty/tools/dotc/transform/ExplicitOuter.scala')
-rw-r--r--src/dotty/tools/dotc/transform/ExplicitOuter.scala10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/transform/ExplicitOuter.scala b/src/dotty/tools/dotc/transform/ExplicitOuter.scala
index d056d7e35..3bef4e263 100644
--- a/src/dotty/tools/dotc/transform/ExplicitOuter.scala
+++ b/src/dotty/tools/dotc/transform/ExplicitOuter.scala
@@ -187,6 +187,10 @@ object ExplicitOuter {
private def hasOuter(cls: ClassSymbol)(implicit ctx: Context): Boolean =
needsOuterIfReferenced(cls) && outerAccessor(cls).exists
+ /** Class constructor takes an outer argument. Can be called only after phase ExplicitOuter. */
+ private def hasOuterParam(cls: ClassSymbol)(implicit ctx: Context): Boolean =
+ !cls.is(Trait) && needsOuterIfReferenced(cls) && outerAccessor(cls).exists
+
/** Tree references a an outer class of `cls` which is not a static owner.
*/
def referencesOuter(cls: Symbol, tree: Tree)(implicit ctx: Context): Boolean = {
@@ -248,7 +252,7 @@ object ExplicitOuter {
/** If `cls` has an outer parameter add one to the method type `tp`. */
def addParam(cls: ClassSymbol, tp: Type): Type =
- if (hasOuter(cls)) {
+ if (hasOuterParam(cls)) {
val mt @ MethodType(pnames, ptypes) = tp
mt.derivedMethodType(
nme.OUTER :: pnames, cls.owner.enclosingClass.typeRef :: ptypes, mt.resultType)
@@ -264,11 +268,11 @@ object ExplicitOuter {
case New(tpt) =>
singleton(outerPrefix(tpt.tpe))
case This(_) =>
- ref(outerParamAccessor(cls)) // will be rewried to outer argument of secondary constructor in phase Constructors
+ ref(outerParamAccessor(cls)) // will be rewired to outer argument of secondary constructor in phase Constructors
case TypeApply(Select(r, nme.asInstanceOf_), args) =>
outerArg(r) // cast was inserted, skip
}
- if (hasOuter(cls))
+ if (hasOuterParam(cls))
methPart(fun) match {
case Select(receiver, _) => outerArg(receiver).withPos(fun.pos) :: Nil
}