diff options
author | Lukas Rytz <lukas.rytz@gmail.com> | 2014-08-20 13:17:16 +0200 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@gmail.com> | 2014-08-20 13:41:01 +0200 |
commit | f324ca5e14d29f8b4f6f7bbacc1c17f4233cd260 (patch) | |
tree | c735c3f233ddadb79b7760a443b29697e2af3bec /src | |
parent | 5e0880fe05fb65a8757721be7e5be6a3259c19a8 (diff) | |
download | scala-f324ca5e14d29f8b4f6f7bbacc1c17f4233cd260.tar.gz scala-f324ca5e14d29f8b4f6f7bbacc1c17f4233cd260.tar.bz2 scala-f324ca5e14d29f8b4f6f7bbacc1c17f4233cd260.zip |
SI-8803 generate super accessor for super[A], if A is outer superclass
class C extends A with T {
class I {
C.super[T]
C.super[A]
}
}
A super call in a nested class of the form super[T] where T is a
parent trait of the outer class doesn't need an accessor: mixin can
directly re-route the call to the correct implementation class - it's
statically known to be T$class.
However, if a nested class accesses super[A] and A is the superclass
of the outer class (not a trait), then we need a super accessor in the
outer class.
We need to add the mixin name to the super accessor name, otherwise
it clashes with non-qualified super accessors.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala | 20 | ||||
-rw-r--r-- | src/reflect/scala/reflect/internal/StdNames.scala | 2 |
2 files changed, 17 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala index 38b00a015b..db81eecdf5 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala @@ -82,11 +82,11 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT val buf = accDefs.getOrElse(clazz, sys.error("no acc def buf for "+clazz)) buf += typers(clazz) typed tree } - private def ensureAccessor(sel: Select) = { + private def ensureAccessor(sel: Select, mixName: TermName = nme.EMPTY) = { val Select(qual, name) = sel val sym = sel.symbol val clazz = qual.symbol - val supername = nme.superName(name) + val supername = nme.superName(name, mixName) val superAcc = clazz.info.decl(supername).suchThat(_.alias == sym) orElse { debuglog(s"add super acc ${sym.fullLocationString} to $clazz") val acc = clazz.newMethod(supername, sel.pos, SUPERACCESSOR | PRIVATE | ARTIFACT) setAlias sym @@ -150,8 +150,20 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT } } - if (name.isTermName && mix == tpnme.EMPTY && (clazz.isTrait || clazz != currentClass || !validCurrentOwner)) - ensureAccessor(sel) + def mixIsTrait = sup.tpe match { + case SuperType(thisTpe, superTpe) => superTpe.typeSymbol.isTrait + } + + val needAccessor = name.isTermName && { + mix.isEmpty && (clazz.isTrait || clazz != currentClass || !validCurrentOwner) || + // SI-8803. If we access super[A] from an inner class (!= currentClass) or closure (validCurrentOwner), + // where A is the superclass we need an accessor. If A is a parent trait we don't: in this case mixin + // will re-route the super call directly to the impl class (it's statically known). + !mix.isEmpty && (clazz != currentClass || !validCurrentOwner) && !mixIsTrait + } + + if (needAccessor) + ensureAccessor(sel, mix.toTermName) else sel } diff --git a/src/reflect/scala/reflect/internal/StdNames.scala b/src/reflect/scala/reflect/internal/StdNames.scala index 6848c357c5..d203218c09 100644 --- a/src/reflect/scala/reflect/internal/StdNames.scala +++ b/src/reflect/scala/reflect/internal/StdNames.scala @@ -473,7 +473,7 @@ trait StdNames { ) def localDummyName(clazz: Symbol): TermName = newTermName(LOCALDUMMY_PREFIX + clazz.name + ">") - def superName(name: Name): TermName = newTermName(SUPER_PREFIX_STRING + name) + def superName(name: Name, mix: Name = EMPTY): TermName = newTermName(SUPER_PREFIX_STRING + name + (if (mix.isEmpty) "" else "$" + mix)) /** The name of an accessor for protected symbols. */ def protName(name: Name): TermName = newTermName(PROTECTED_PREFIX + name) |