diff --git a/compiler/src/dotty/tools/dotc/transform/Bridges.scala b/compiler/src/dotty/tools/dotc/transform/Bridges.scala index 4cdb96e83c0c..1e7f79a7c9df 100644 --- a/compiler/src/dotty/tools/dotc/transform/Bridges.scala +++ b/compiler/src/dotty/tools/dotc/transform/Bridges.scala @@ -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) } @@ -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 diff --git a/tests/run/mixin-signatures.check b/tests/run/mixin-signatures.check index 98979ab8d99b..30593d791c0a 100644 --- a/tests/run/mixin-signatures.check +++ b/tests/run/mixin-signatures.check @@ -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) 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) 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) 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) public default java.lang.Object Base.h(java.lang.Object) generic: public default R Base.h(T) } diff --git a/tests/run/trait-bridge-signatures.check b/tests/run/trait-bridge-signatures.check index 26de5b586b90..345645e1ec84 100644 --- a/tests/run/trait-bridge-signatures.check +++ b/tests/run/trait-bridge-signatures.check @@ -27,8 +27,7 @@ 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() } interface collections$LinearSeq { @@ -36,8 +35,7 @@ interface collections$LinearSeq { - 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() } interface collections$Iterable { @@ -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) - public default play$StandaloneWSRequest play$StandaloneWSRequest.addCookies(scala.collection.immutable.Seq) - - generic: public default play$StandaloneWSRequest play$StandaloneWSRequest.addCookies(scala.collection.immutable.Seq) - public abstract play$StandaloneWSRequest play$StandaloneWSRequest.withCookies(scala.collection.immutable.Seq) - - generic: public abstract play$StandaloneWSRequest play$StandaloneWSRequest.withCookies(scala.collection.immutable.Seq) + public default play$StandaloneWSRequest play$WSRequest.addCookies(scala.collection.immutable.Seq) + 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) + public default play$StandaloneWSRequest play$WSRequest.withCookies(scala.collection.immutable.Seq) + public static play$StandaloneWSRequest play$WSRequest.withCookies$(play$WSRequest,scala.collection.immutable.Seq) }