Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.

Commit 39afd13

Browse files
committed
Merge pull request scala#4560 from adriaanm/t9356
SI-9356 more careful assertion in back-end
2 parents f0388d2 + f8fbd5d commit 39afd13

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -617,18 +617,16 @@ abstract class GenASM extends SubComponent with BytecodeWriters { self =>
617617
val internalName = cachedJN.toString()
618618
val trackedSym = jsymbol(sym)
619619
reverseJavaName.get(internalName) match {
620-
case Some(oldsym) if oldsym.exists && trackedSym.exists =>
621-
assert(
622-
// In contrast, neither NothingClass nor NullClass show up bytecode-level.
623-
(oldsym == trackedSym) || (oldsym == RuntimeNothingClass) || (oldsym == RuntimeNullClass) || (oldsym.isModuleClass && (oldsym.sourceModule == trackedSym.sourceModule)),
624-
s"""|Different class symbols have the same bytecode-level internal name:
625-
| name: $internalName
626-
| oldsym: ${oldsym.fullNameString}
627-
| tracked: ${trackedSym.fullNameString}
628-
""".stripMargin
629-
)
630-
case _ =>
620+
case None =>
631621
reverseJavaName.put(internalName, trackedSym)
622+
case Some(oldsym) =>
623+
// TODO: `duplicateOk` seems pretty ad-hoc (a more aggressive version caused SI-9356 because it called oldSym.exists, which failed in the unpickler; see also SI-5031)
624+
def duplicateOk = oldsym == NoSymbol || trackedSym == NoSymbol || (syntheticCoreClasses contains oldsym) || (oldsym.isModuleClass && (oldsym.sourceModule == trackedSym.sourceModule))
625+
if (oldsym != trackedSym && !duplicateOk)
626+
devWarning(s"""|Different class symbols have the same bytecode-level internal name:
627+
| name: $internalName
628+
| oldsym: ${oldsym.fullNameString}
629+
| tracked: ${trackedSym.fullNameString}""".stripMargin)
632630
}
633631
}
634632

test/files/pos/t9356/Foo_2.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class C
2+
3+
trait Foo {
4+
@annot.MyAnnotation(cls = classOf[C])
5+
def function: Any = ???
6+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package annot;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
@Target(ElementType.METHOD)
9+
@Retention(RetentionPolicy.RUNTIME)
10+
public @interface MyAnnotation {
11+
Class<?> cls();
12+
}

test/files/pos/t9356/Test_3.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Foo1 extends Foo
2+
3+
class Foo2 extends Foo

0 commit comments

Comments
 (0)