Skip to content

Commit 82721bc

Browse files
committed
Simplify classfile parser "own name" checking
Simplifies the test that the class represented by a classfile is the class logically referenced by the file. The simplification is needed if we want to populate package scopes with unmangled classnames.
1 parent 82b9282 commit 82721bc

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ class ClassfileParser(
3939
protected val staticScope: MutableScope = newScope // the scope of all static definitions
4040
protected var pool: ConstantPool = _ // the classfile's constant pool
4141

42-
protected var currentClassName: Name = _ // JVM name of the current class
42+
protected var currentClassName: SimpleTermName = _ // JVM name of the current class
4343
protected var classTParams = Map[Name,Symbol]()
4444

4545
classRoot.info = (new NoCompleter).withDecls(instanceScope)
4646
moduleRoot.info = (new NoCompleter).withDecls(staticScope).withSourceModule(_ => staticModule)
4747

4848
private def currentIsTopLevel(implicit ctx: Context) = classRoot.owner is Flags.PackageClass
4949

50-
private def mismatchError(c: Symbol) =
51-
throw new IOException(s"class file '${in.file}' has location not matching its contents: contains $c")
50+
private def mismatchError(className: SimpleTermName) =
51+
throw new IOException(s"class file '${in.file}' has location not matching its contents: contains class $className")
5252

5353
def run()(implicit ctx: Context): Option[Embedded] = try {
5454
ctx.debuglog("[class] >> " + classRoot.fullName)
@@ -92,15 +92,8 @@ class ClassfileParser(
9292
val nameIdx = in.nextChar
9393
currentClassName = pool.getClassName(nameIdx)
9494

95-
if (currentIsTopLevel) {
96-
val c = pool.getClassSymbol(nameIdx)
97-
if (c != classRoot.symbol) {
98-
println(currentClassName.debugString) // TODO: remove
99-
println(c.name.debugString)
100-
println(classRoot.symbol.name.debugString)
101-
mismatchError(c)
102-
}
103-
}
95+
if (currentIsTopLevel && currentClassName != classRoot.fullName.toSimpleName)
96+
mismatchError(currentClassName)
10497

10598
addEnclosingTParams()
10699

0 commit comments

Comments
 (0)