diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2013-07-17 15:52:48 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2013-07-28 07:38:16 +0200 |
commit | 050b4c951c838699c2fe30cbf01b63942c63a299 (patch) | |
tree | b74d134cbfc14b3dad08162cf6126296ca285df6 /src/compiler/scala/tools/nsc/symtab | |
parent | 54cb6af7dbcf630a4f57e98f0099d77dd3b36693 (diff) | |
download | scala-050b4c951c838699c2fe30cbf01b63942c63a299.tar.gz scala-050b4c951c838699c2fe30cbf01b63942c63a299.tar.bz2 scala-050b4c951c838699c2fe30cbf01b63942c63a299.zip |
SI-7455 Drop dummy param for synthetic access constructor
Java synthesizes public constructors in private classes to
allow access from inner classes. The signature of
that synthetic constructor (known as a "access constructor")
has a dummy parameter appended to avoid overloading clashes.
javac chooses the type "Enclosing$1" for the dummy parameter
(called the "access constructor tag") which is either an
existing anonymous class or a synthesized class for this purpose.
In OpenJDK, this transformation is performed in:
langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java
(Incidentally, scalac would just emits a byte-code public
constructor in this situation, rather than a private constructor /
access constructor pair.)
Scala parses the signature of the access contructor, and drops
the $outer parameter, but retains the dummy parameter. This causes
havoc when it tries to parse the bytecode for that anonymous class;
the class file parser doesn't have the enclosing type parameters
of Vector in scope and crash ensues.
In any case, we shouldn't allow user code to see that constructor;
it should only be called from within its own compilation unit.
This commit drops the dummy parameter from access constructor
signatures in class file parsing.
Diffstat (limited to 'src/compiler/scala/tools/nsc/symtab')
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index da117540b4..4e5204f283 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -626,7 +626,7 @@ abstract class ClassfileParser { sawPrivateConstructor = true in.skip(2); skipAttributes() } else { - if ((sflags & PRIVATE) != 0L && global.settings.optimise.value) { + if ((sflags & PRIVATE) != 0L && global.settings.optimise.value) { // TODO this should be !optimize, no? See c4181f656d. in.skip(4); skipAttributes() } else { val name = pool.getName(in.nextChar) @@ -636,7 +636,7 @@ abstract class ClassfileParser { info match { case MethodType(params, restpe) => // if this is a non-static inner class, remove the explicit outer parameter - val newParams = innerClasses getEntry currentClass match { + val paramsNoOuter = innerClasses getEntry currentClass match { case Some(entry) if !isScalaRaw && !isStatic(entry.jflags) => /* About `clazz.owner.isPackage` below: SI-5957 * For every nested java class A$B, there are two symbols in the scala compiler. @@ -650,6 +650,15 @@ abstract class ClassfileParser { case _ => params } + val newParams = paramsNoOuter match { + case (init :+ tail) if (jflags & JAVA_ACC_SYNTHETIC) != 0L => + // SI-7455 strip trailing dummy argument ("access constructor tag") from synthetic constructors which + // are added when an inner class needs to access a private constructor. + init + case _ => + paramsNoOuter + } + info = MethodType(newParams, clazz.tpe) } sym.setInfo(info) |