Skip to content

Fix #1905: Duplicate bridge #1906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/Erasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ object Erasure extends TypeTestsCasts{
// this implementation doesn't check for bridge clashes with value types!
def addBridges(oldStats: List[untpd.Tree], newStats: List[tpd.Tree])(implicit ctx: Context): List[tpd.Tree] = {
val beforeCtx = ctx.withPhase(ctx.erasurePhase)
val afterCtx = ctx.withPhase(ctx.elimErasedValueTypePhase.next)
def traverse(after: List[Tree], before: List[untpd.Tree],
emittedBridges: ListBuffer[tpd.DefDef] = ListBuffer[tpd.DefDef]()): List[tpd.DefDef] = {
after match {
Expand All @@ -613,7 +614,7 @@ object Erasure extends TypeTestsCasts{
val newSymbol = member.symbol(ctx)
assert(oldSymbol.name(beforeCtx) == newSymbol.name,
s"${oldSymbol.name(beforeCtx)} bridging with ${newSymbol.name}")
val newOverridden = oldSymbol.denot.allOverriddenSymbols.toSet // TODO: clarify new <-> old in a comment; symbols are swapped here
val newOverridden = oldSymbol.denot.allOverriddenSymbols(afterCtx).toSet // TODO: clarify new <-> old in a comment; symbols are swapped here
val oldOverridden = newSymbol.allOverriddenSymbols(beforeCtx).toSet // TODO: can we find a more efficient impl? newOverridden does not have to be a set!
def stillInBaseClass(sym: Symbol) = ctx.owner derivesFrom sym.owner
val neededBridges = (oldOverridden -- newOverridden).filter(stillInBaseClass)
Expand Down
20 changes: 20 additions & 0 deletions tests/run/iarray.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import scala.reflect.ClassTag

class Arr[T](private val underlying: scala.Array[T]) extends AnyVal {
def toList = underlying.toList
}

trait SeqMonoTransforms[+A, +Repr] extends Any {
protected[this] def fromIterableWithSameElemType(): Repr
}

class ArrOps[A](val xs: Arr[A]) extends AnyRef with SeqMonoTransforms[A, Arr[A]] {
def fromIterableWithSameElemType(): Arr[A] = xs
}

object Test {
def main(args: Array[String]) =
assert(new ArrOps(new Arr(Array(1, 2, 3))).fromIterableWithSameElemType.toList ==
List(1, 2, 3))
}