Skip to content

Commit 82b9282

Browse files
committed
Don't unmangle names in ClassfileParser
Classfile parsing is about JVM-level names, not Scala level ones. So it is more consistent to use mangled names throughout.
1 parent 08050d7 commit 82b9282

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -247,22 +247,21 @@ class ClassfileParser(
247247
final def objToAny(tp: Type)(implicit ctx: Context) =
248248
if (tp.isDirectRef(defn.ObjectClass) && !ctx.phase.erasedTypes) defn.AnyType else tp
249249

250-
private def sigToType(signature: TermName, owner: Symbol = null)(implicit ctx: Context): Type = {
251-
val sig = signature.toSimpleName
250+
private def sigToType(sig: SimpleTermName, owner: Symbol = null)(implicit ctx: Context): Type = {
252251
var index = 0
253252
val end = sig.length
254253
def accept(ch: Char): Unit = {
255254
assert(sig(index) == ch, (sig(index), ch))
256255
index += 1
257256
}
258-
def subName(isDelimiter: Char => Boolean): TermName = {
257+
def subName(isDelimiter: Char => Boolean): SimpleTermName = {
259258
val start = index
260259
while (!isDelimiter(sig(index))) { index += 1 }
261-
sig.slice(start, index).asTermName
260+
sig.slice(start, index)
262261
}
263262
// Warning: sigToType contains nested completers which might be forced in a later run!
264263
// So local methods need their own ctx parameters.
265-
def sig2type(tparams: immutable.Map[Name,Symbol], skiptvs: Boolean)(implicit ctx: Context): Type = {
264+
def sig2type(tparams: immutable.Map[Name, Symbol], skiptvs: Boolean)(implicit ctx: Context): Type = {
266265
val tag = sig(index); index += 1
267266
(tag: @switch) match {
268267
case BYTE_TAG => defn.ByteType
@@ -895,7 +894,7 @@ class ClassfileParser(
895894
private val len = in.nextChar
896895
private val starts = new Array[Int](len)
897896
private val values = new Array[AnyRef](len)
898-
private val internalized = new Array[TermName](len)
897+
private val internalized = new Array[SimpleTermName](len)
899898

900899
{ var i = 1
901900
while (i < starts.length) {
@@ -922,12 +921,12 @@ class ClassfileParser(
922921
}
923922

924923
/** Return the name found at given index. */
925-
def getName(index: Int): TermName = {
924+
def getName(index: Int): SimpleTermName = {
926925
if (index <= 0 || len <= index)
927926
errorBadIndex(index)
928927

929928
values(index) match {
930-
case name: TermName => name
929+
case name: SimpleTermName => name
931930
case null =>
932931
val start = starts(index)
933932
if (in.buf(start).toInt != CONSTANT_UTF8) errorBadTag(start)
@@ -938,12 +937,12 @@ class ClassfileParser(
938937
}
939938

940939
/** Return the name found at given index in the constant pool, with '/' replaced by '.'. */
941-
def getExternalName(index: Int): TermName = {
940+
def getExternalName(index: Int): SimpleTermName = {
942941
if (index <= 0 || len <= index)
943942
errorBadIndex(index)
944943

945944
if (internalized(index) == null)
946-
internalized(index) = getName(index).replace('/', '.').unmangleClassName
945+
internalized(index) = getName(index).replace('/', '.')
947946

948947
internalized(index)
949948
}
@@ -955,9 +954,9 @@ class ClassfileParser(
955954
val start = starts(index)
956955
if (in.buf(start).toInt != CONSTANT_CLASS) errorBadTag(start)
957956
val name = getExternalName(in.getChar(start + 1))
958-
if (name.is(ModuleClassName) && (name ne nme.nothingRuntimeClass) && (name ne nme.nullRuntimeClass))
957+
if (name.endsWith("$") && (name ne nme.nothingRuntimeClass) && (name ne nme.nullRuntimeClass))
959958
// Null$ and Nothing$ ARE classes
960-
c = ctx.requiredModule(name.sourceModuleName)
959+
c = ctx.requiredModule(name.dropRight(1))
961960
else c = classNameToSymbol(name)
962961
values(index) = c
963962
}
@@ -967,7 +966,7 @@ class ClassfileParser(
967966
/** Return the external name of the class info structure found at 'index'.
968967
* Use 'getClassSymbol' if the class is sure to be a top-level class.
969968
*/
970-
def getClassName(index: Int): TermName = {
969+
def getClassName(index: Int): SimpleTermName = {
971970
val start = starts(index)
972971
if (in.buf(start).toInt != CONSTANT_CLASS) errorBadTag(start)
973972
getExternalName(in.getChar(start + 1))

0 commit comments

Comments
 (0)