Skip to content

Commit bd10895

Browse files
committed
Fix scala#1905: Duplicate bridge
The problem with scala#1905 was that we checked "new" overriding relationships are phase erasure + 1. This is wrong when we have ErasedValueTypes because these do not compare correctly ith their underlying type. So we get spurious mismatches which force in turn spurious bridge generation. The fix is to compute newly overridden symbols at phase elimErasedValueTypes + 1, i.e. one phase later.
1 parent dc32420 commit bd10895

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ object Erasure extends TypeTestsCasts{
600600
// this implementation doesn't check for bridge clashes with value types!
601601
def addBridges(oldStats: List[untpd.Tree], newStats: List[tpd.Tree])(implicit ctx: Context): List[tpd.Tree] = {
602602
val beforeCtx = ctx.withPhase(ctx.erasurePhase)
603+
val afterCtx = ctx.withPhase(ctx.elimErasedValueTypePhase.next)
603604
def traverse(after: List[Tree], before: List[untpd.Tree],
604605
emittedBridges: ListBuffer[tpd.DefDef] = ListBuffer[tpd.DefDef]()): List[tpd.DefDef] = {
605606
after match {
@@ -613,7 +614,7 @@ object Erasure extends TypeTestsCasts{
613614
val newSymbol = member.symbol(ctx)
614615
assert(oldSymbol.name(beforeCtx) == newSymbol.name,
615616
s"${oldSymbol.name(beforeCtx)} bridging with ${newSymbol.name}")
616-
val newOverridden = oldSymbol.denot.allOverriddenSymbols.toSet // TODO: clarify new <-> old in a comment; symbols are swapped here
617+
val newOverridden = oldSymbol.denot.allOverriddenSymbols(afterCtx).toSet // TODO: clarify new <-> old in a comment; symbols are swapped here
617618
val oldOverridden = newSymbol.allOverriddenSymbols(beforeCtx).toSet // TODO: can we find a more efficient impl? newOverridden does not have to be a set!
618619
def stillInBaseClass(sym: Symbol) = ctx.owner derivesFrom sym.owner
619620
val neededBridges = (oldOverridden -- newOverridden).filter(stillInBaseClass)

0 commit comments

Comments
 (0)