aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorodersky <odersky@gmail.com>2017-04-12 09:08:10 +0200
committerGitHub <noreply@github.com>2017-04-12 09:08:10 +0200
commit741ee1645a13c94fbb7edfd064b4ec092a69b1bf (patch)
tree455ce71857af352371c555508fcdb598bb11ae30
parent4b33e362b438ee14abf52d1803db42383c9c4013 (diff)
parentcc4045fb39d777785e315f3003959724ead13b88 (diff)
downloaddotty-741ee1645a13c94fbb7edfd064b4ec092a69b1bf.tar.gz
dotty-741ee1645a13c94fbb7edfd064b4ec092a69b1bf.tar.bz2
dotty-741ee1645a13c94fbb7edfd064b4ec092a69b1bf.zip
Merge pull request #2229 from dotty-staging/sync-classfile-parser
Port some ClassfileParser changes from scalac
-rw-r--r--compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala34
-rw-r--r--tests/disabled/run/t5293.scala (renamed from tests/run/t5293.scala)0
-rw-r--r--tests/run/t9915/C_1.java20
-rw-r--r--tests/run/t9915/Test_2.scala12
4 files changed, 57 insertions, 9 deletions
diff --git a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala
index 26c823f97..9415c047f 100644
--- a/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala
+++ b/compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala
@@ -7,7 +7,7 @@ import Contexts._, Symbols._, Types._, Names._, StdNames._, NameOps._, Scopes._,
import SymDenotations._, unpickleScala2.Scala2Unpickler._, Constants._, Annotations._, util.Positions._
import NameKinds.{ModuleClassName, DefaultGetterName}
import ast.tpd._
-import java.io.{ File, IOException }
+import java.io.{ ByteArrayInputStream, DataInputStream, File, IOException }
import java.lang.Integer.toHexString
import scala.collection.{ mutable, immutable }
import scala.collection.mutable.{ ListBuffer, ArrayBuffer }
@@ -194,13 +194,21 @@ class ClassfileParser(
val name = pool.getName(in.nextChar)
val isConstructor = name eq nme.CONSTRUCTOR
- /** Strip leading outer param from constructor.
- * Todo: Also strip trailing access tag for private inner constructors?
+ /** Strip leading outer param from constructor and trailing access tag for
+ * private inner constructors.
*/
- def stripOuterParamFromConstructor() = innerClasses.get(currentClassName) match {
+ def normalizeConstructorParams() = innerClasses.get(currentClassName) match {
case Some(entry) if !isStatic(entry.jflags) =>
val mt @ MethodTpe(paramNames, paramTypes, resultType) = denot.info
- denot.info = mt.derivedLambdaType(paramNames.tail, paramTypes.tail, resultType)
+ var normalizedParamNames = paramNames.tail
+ var normalizedParamTypes = paramTypes.tail
+ if ((jflags & JAVA_ACC_SYNTHETIC) != 0) {
+ // 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.
+ normalizedParamNames = paramNames.dropRight(1)
+ normalizedParamTypes = paramTypes.dropRight(1)
+ }
+ denot.info = mt.derivedLambdaType(normalizedParamNames, normalizedParamTypes, resultType)
case _ =>
}
@@ -216,7 +224,7 @@ class ClassfileParser(
denot.info = pool.getType(in.nextChar)
if (isEnum) denot.info = ConstantType(Constant(sym))
- if (isConstructor) stripOuterParamFromConstructor()
+ if (isConstructor) normalizeConstructorParams()
setPrivateWithin(denot, jflags)
denot.info = translateTempPoly(parseAttributes(sym, denot.info))
if (isConstructor) normalizeConstructorInfo()
@@ -227,8 +235,12 @@ class ClassfileParser(
// seal java enums
if (isEnum) {
val enumClass = sym.owner.linkedClass
- if (!(enumClass is Flags.Sealed)) enumClass.setFlag(Flags.AbstractSealed)
- enumClass.addAnnotation(Annotation.makeChild(sym))
+ if (!enumClass.exists)
+ ctx.warning(s"no linked class for java enum $sym in ${sym.owner}. A referencing class file might be missing an InnerClasses entry.")
+ else {
+ if (!(enumClass is Flags.Sealed)) enumClass.setFlag(Flags.AbstractSealed)
+ enumClass.addAnnotation(Annotation.makeChild(sym))
+ }
}
} finally {
in.bp = oldbp
@@ -923,12 +935,16 @@ class ClassfileParser(
case null =>
val start = starts(index)
if (in.buf(start).toInt != CONSTANT_UTF8) errorBadTag(start)
- val name = termName(in.buf, start + 3, in.getChar(start + 1))
+ val len = in.getChar(start + 1).toInt
+ val name = termName(fromMUTF8(in.buf, start + 1, len + 2))
values(index) = name
name
}
}
+ private def fromMUTF8(bytes: Array[Byte], offset: Int, len: Int): String =
+ new DataInputStream(new ByteArrayInputStream(bytes, offset, len)).readUTF
+
/** Return the name found at given index in the constant pool, with '/' replaced by '.'. */
def getExternalName(index: Int): SimpleTermName = {
if (index <= 0 || len <= index)
diff --git a/tests/run/t5293.scala b/tests/disabled/run/t5293.scala
index 8a99989c5..8a99989c5 100644
--- a/tests/run/t5293.scala
+++ b/tests/disabled/run/t5293.scala
diff --git a/tests/run/t9915/C_1.java b/tests/run/t9915/C_1.java
new file mode 100644
index 000000000..4269cf74e
--- /dev/null
+++ b/tests/run/t9915/C_1.java
@@ -0,0 +1,20 @@
+/*
+ * javac: -encoding UTF-8
+ */
+public class C_1 {
+ public static final String NULLED = "X\000ABC";
+ public static final String SUPPED = "𐒈𐒝𐒑𐒛𐒐𐒘𐒕𐒖";
+
+ public String nulled() {
+ return C_1.NULLED;
+ }
+ public String supped() {
+ return C_1.SUPPED;
+ }
+ public int nulledSize() {
+ return C_1.NULLED.length();
+ }
+ public int suppedSize() {
+ return C_1.SUPPED.length();
+ }
+}
diff --git a/tests/run/t9915/Test_2.scala b/tests/run/t9915/Test_2.scala
new file mode 100644
index 000000000..afed667cc
--- /dev/null
+++ b/tests/run/t9915/Test_2.scala
@@ -0,0 +1,12 @@
+
+object Test extends App {
+ val c = new C_1
+ assert(c.nulled == "X\u0000ABC") // "X\000ABC"
+ assert(c.supped == "𐒈𐒝𐒑𐒛𐒐𐒘𐒕𐒖")
+
+ assert(C_1.NULLED == "X\u0000ABC") // "X\000ABC"
+ assert(C_1.SUPPED == "𐒈𐒝𐒑𐒛𐒐𐒘𐒕𐒖")
+
+ assert(C_1.NULLED.size == "XYABC".size)
+ assert(C_1.SUPPED.codePointCount(0, C_1.SUPPED.length) == 8)
+}