Skip to content

Commit 60d462e

Browse files
committed
Merge pull request scala#2608 from retronym/ticket/7532
SI-7532 Fix regression in Java inner classfile reader
2 parents d16786d + 75251f7 commit 60d462e

File tree

5 files changed

+30
-4
lines changed

5 files changed

+30
-4
lines changed

src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ abstract class ClassfileParser {
4444

4545
def srcfile = srcfile0
4646

47-
private def currentIsTopLevel = !(currentClass.decodedName containsChar '$')
48-
4947
private object unpickler extends scala.reflect.internal.pickling.UnPickler {
5048
val global: ClassfileParser.this.global.type = ClassfileParser.this.global
5149
}
@@ -515,8 +513,10 @@ abstract class ClassfileParser {
515513
}
516514
}
517515

518-
val c = if (currentIsTopLevel) pool.getClassSymbol(nameIdx) else clazz
519-
if (currentIsTopLevel) {
516+
val isTopLevel = !(currentClass containsChar '$') // Java class name; *don't* try to to use Scala name decoding (SI-7532)
517+
518+
val c = if (isTopLevel) pool.getClassSymbol(nameIdx) else clazz
519+
if (isTopLevel) {
520520
if (c != clazz) {
521521
if ((clazz eq NoSymbol) && (c ne NoSymbol)) clazz = c
522522
else mismatchError(c)

test/files/pos/t7532/A_1.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class R {
2+
public class attr { // Will have the bytecode name `R$attr`, not to be confused with `R@tr`!
3+
}
4+
public static class attr1 {
5+
}
6+
}

test/files/pos/t7532/B_2.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object Test {
2+
val r = new R
3+
new r.attr() // Was: error while loading attr, class file '.../t7532-pos.obj/R$attr.class' has location not matching its contents: contains class
4+
new R.attr1
5+
}

test/files/pos/t7532b/A_1.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package pack
2+
class R {
3+
class attr // Will have the bytecode name `R$attr`, not to be confused with `R@tr`!
4+
class `@`
5+
}
6+
7+
class `@`

test/files/pos/t7532b/B_2.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import pack._
2+
3+
object Test {
4+
val r = new R
5+
new r.attr()
6+
new r.`@`
7+
new `@`
8+
}

0 commit comments

Comments
 (0)