Skip to content

Commit

Permalink
Always generate bridges in traits - makes the trait-bridge-signatures…
Browse files Browse the repository at this point in the history
….play reproducer compliant with Java counterpart
  • Loading branch information
WojciechMazur committed May 31, 2024
1 parent 2d69f6d commit e52535f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 25 deletions.
14 changes: 5 additions & 9 deletions compiler/src/dotty/tools/dotc/transform/Bridges.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,11 @@ class Bridges(root: ClassSymbol, thisPhase: DenotTransformer)(using Context) {
*/
private class TraitBridgesCursor(using Context) extends BridgesCursor{
override protected def prioritizeDeferred: Boolean = false

// Get full list of parents to deduplicate already defined bridges in the parents
override lazy val parents: Array[Symbol] =
root.info.parents.map(_.classSymbol).toArray

override protected def matches(sym: Symbol, overriden: Symbol): Boolean =
def resultType(sym: Symbol) = sym.info.finalResultType.typeSymbol
def consistentParams = sym.signature.consistentParams(overriden.signature)
def overridesAbstractResultType = resultType(overriden).isAbstractOrParamType
consistentParams && !overridesAbstractResultType && super.matches(sym, overriden)

override def exclude(sym: Symbol) =
!sym.isPublic || super.exclude(sym)
}
Expand Down Expand Up @@ -194,12 +189,13 @@ class Bridges(root: ClassSymbol, thisPhase: DenotTransformer)(using Context) {
* time deferred methods in `stats` that are replaced by a bridge with the same signature.
*/
def add(stats: List[untpd.Tree]): List[untpd.Tree] =
val forTrait = root.is(Trait)
val opc = inContext(preErasureCtx) {
if (root.is(Trait)) new TraitBridgesCursor
else new BridgesCursor
if forTrait then TraitBridgesCursor()
else BridgesCursor()
}
while opc.hasNext do
if !opc.overriding.is(Deferred) then
if forTrait || !opc.overriding.is(Deferred) then
addBridgeIfNeeded(opc.overriding, opc.overridden)
opc.next()
if bridges.isEmpty then stats
Expand Down
12 changes: 4 additions & 8 deletions tests/run/mixin-signatures.check
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,23 @@ class Test$bar5$ {
}

interface Foo1 {
public abstract java.lang.Object Base.f(java.lang.Object)
generic: public abstract R Base.f(T)
public default java.lang.String Foo1.f(java.lang.Object)
generic: public default java.lang.String Foo1.f(T)
public abstract java.lang.Object Base.g(java.lang.Object)
generic: public abstract R Base.g(T)
public default java.lang.Object Foo1.f(java.lang.Object) <bridge> <synthetic>
public abstract java.lang.String Foo1.g(java.lang.Object)
generic: public abstract java.lang.String Foo1.g(T)
public default java.lang.Object Foo1.g(java.lang.Object) <bridge> <synthetic>
public default java.lang.Object Base.h(java.lang.Object)
generic: public default R Base.h(T)
}

interface Foo2 {
public abstract java.lang.Object Base.f(java.lang.Object)
generic: public abstract R Base.f(T)
public default java.lang.Object Foo2.f(java.lang.String)
generic: public default R Foo2.f(java.lang.String)
public abstract java.lang.Object Base.g(java.lang.Object)
generic: public abstract R Base.g(T)
public default java.lang.Object Foo2.f(java.lang.Object) <bridge> <synthetic>
public abstract java.lang.Object Foo2.g(java.lang.String)
generic: public abstract R Foo2.g(java.lang.String)
public default java.lang.Object Foo2.g(java.lang.Object) <bridge> <synthetic>
public default java.lang.Object Base.h(java.lang.Object)
generic: public default R Base.h(T)
}
Expand Down
14 changes: 6 additions & 8 deletions tests/run/trait-bridge-signatures.check
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,15 @@ interface collections$LinearSeqOps {
- generic: public abstract A collections$LinearSeqOps.head()
public abstract collections$LinearSeq collections$LinearSeqOps.tail()
- generic: public abstract C collections$LinearSeqOps.tail()
public default java.lang.Object collections$IterableOps.tail()
- generic: public default C collections$IterableOps.tail()
public default java.lang.Object collections$LinearSeqOps.tail() <bridge> <synthetic>
}

interface collections$LinearSeq {
public abstract java.lang.Object collections$LinearSeqOps.head()
- generic: public abstract A collections$LinearSeqOps.head()
public abstract collections$LinearSeq collections$LinearSeqOps.tail()
- generic: public abstract C collections$LinearSeqOps.tail()
public default java.lang.Object collections$IterableOps.tail()
- generic: public default C collections$IterableOps.tail()
public default java.lang.Object collections$LinearSeqOps.tail() <bridge> <synthetic>
}

interface collections$Iterable {
Expand Down Expand Up @@ -75,11 +73,11 @@ class EmptyCollection {
interface play$WSRequest {
public abstract play$WSRequest play$WSRequest.addCookies(scala.collection.immutable.Seq)
- generic: public abstract play$WSRequest play$WSRequest.addCookies(scala.collection.immutable.Seq<play$WSCookie>)
public default play$StandaloneWSRequest play$StandaloneWSRequest.addCookies(scala.collection.immutable.Seq)
- generic: public default play$StandaloneWSRequest play$StandaloneWSRequest.addCookies(scala.collection.immutable.Seq<play$WSCookie>)
public abstract play$StandaloneWSRequest play$StandaloneWSRequest.withCookies(scala.collection.immutable.Seq)
- generic: public abstract play$StandaloneWSRequest play$StandaloneWSRequest.withCookies(scala.collection.immutable.Seq<play$WSCookie>)
public default play$StandaloneWSRequest play$WSRequest.addCookies(scala.collection.immutable.Seq) <bridge> <synthetic>
public static play$StandaloneWSRequest play$WSRequest.addCookies$(play$WSRequest,scala.collection.immutable.Seq)
public abstract play$WSRequest play$WSRequest.withCookies(scala.collection.immutable.Seq)
- generic: public abstract play$WSRequest play$WSRequest.withCookies(scala.collection.immutable.Seq<play$WSCookie>)
public default play$StandaloneWSRequest play$WSRequest.withCookies(scala.collection.immutable.Seq) <bridge> <synthetic>
public static play$StandaloneWSRequest play$WSRequest.withCookies$(play$WSRequest,scala.collection.immutable.Seq)
}

0 comments on commit e52535f

Please sign in to comment.