Skip to content

Commit 2d69f6d

Browse files
committed
Allow to skip priotirization of decls in the TraitBridgesCursor - fixes bridges generated in play-framework
1 parent fe2a1a1 commit 2d69f6d

File tree

4 files changed

+46
-8
lines changed

4 files changed

+46
-8
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class Bridges(root: ClassSymbol, thisPhase: DenotTransformer)(using Context) {
5050
* We also ignore non-public methods (see `DottyBackendTests.invocationReceivers` for a test case).
5151
*/
5252
private class TraitBridgesCursor(using Context) extends BridgesCursor{
53+
override protected def prioritizeDeferred: Boolean = false
5354
// Get full list of parents to deduplicate already defined bridges in the parents
5455
override lazy val parents: Array[Symbol] =
5556
root.info.parents.map(_.classSymbol).toArray

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,25 +49,35 @@ object OverridingPairs:
4949
protected def matches(sym1: Symbol, sym2: Symbol): Boolean =
5050
sym1.isType || sym1.asSeenFrom(self).matches(sym2.asSeenFrom(self))
5151

52+
/** Should deffered declarations took precedence over the concreate defintions
53+
* In same cases, eg. trait bridges, cursor might lead to incorrect results
54+
* when overriden and overriding methods would be swapped leading to incorrect behaviour
55+
*/
56+
protected def prioritizeDeferred = true
57+
5258
/** The symbols that can take part in an overriding pair */
53-
private val decls = {
59+
val decls = {
5460
val decls = newScope
5561
// fill `decls` with overriding shadowing overridden */
56-
def fillDecls(bcs: List[Symbol], deferred: Boolean): Unit = bcs match {
62+
def fillDecls(bcs: List[Symbol], include: Symbol => Boolean): Unit = bcs match {
5763
case bc :: bcs1 =>
58-
fillDecls(bcs1, deferred)
64+
fillDecls(bcs1, include)
5965
var e = bc.info.decls.lastEntry
6066
while (e != null) {
61-
if (e.sym.is(Deferred) == deferred && !exclude(e.sym))
67+
if (include(e.sym) && !exclude(e.sym))
6268
decls.enter(e.sym)
6369
e = e.prev
6470
}
6571
case nil =>
6672
}
67-
// first, deferred (this will need to change if we change lookup rules!
68-
fillDecls(base.info.baseClasses, deferred = true)
69-
// then, concrete.
70-
fillDecls(base.info.baseClasses, deferred = false)
73+
val baseClasses = base.info.baseClasses
74+
if prioritizeDeferred then
75+
// first, deferred (this will need to change if we change lookup rules!
76+
fillDecls(baseClasses, _.is(Deferred))
77+
// then, concrete.
78+
fillDecls(baseClasses, !_.is(Deferred))
79+
else
80+
fillDecls(baseClasses, _ => true)
7181
decls
7282
}
7383

tests/run/trait-bridge-signatures.check

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,14 @@ class EmptyCollection {
7272
- generic: public static <C> PartialFunc<java.lang.Object, C> EmptyCollection.andThen(Func1<scala.runtime.Nothing$, C>)
7373
}
7474

75+
interface play$WSRequest {
76+
public abstract play$WSRequest play$WSRequest.addCookies(scala.collection.immutable.Seq)
77+
- generic: public abstract play$WSRequest play$WSRequest.addCookies(scala.collection.immutable.Seq<play$WSCookie>)
78+
public default play$StandaloneWSRequest play$StandaloneWSRequest.addCookies(scala.collection.immutable.Seq)
79+
- generic: public default play$StandaloneWSRequest play$StandaloneWSRequest.addCookies(scala.collection.immutable.Seq<play$WSCookie>)
80+
public abstract play$StandaloneWSRequest play$StandaloneWSRequest.withCookies(scala.collection.immutable.Seq)
81+
- generic: public abstract play$StandaloneWSRequest play$StandaloneWSRequest.withCookies(scala.collection.immutable.Seq<play$WSCookie>)
82+
public abstract play$WSRequest play$WSRequest.withCookies(scala.collection.immutable.Seq)
83+
- generic: public abstract play$WSRequest play$WSRequest.withCookies(scala.collection.immutable.Seq<play$WSCookie>)
84+
}
85+

tests/run/trait-bridge-signatures.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,20 @@ trait Collection[+A] extends PartialFunc[Int, A] {
7171
}
7272
case object EmptyCollection extends Collection[Nothing]
7373

74+
object play {
75+
trait WSCookie
76+
trait StandaloneWSRequest {
77+
type Self <: StandaloneWSRequest { type Self = StandaloneWSRequest.this.Self }
78+
def withCookies(cookies: WSCookie*): Self
79+
def addCookies(cookies: WSCookie*): Self = ???
80+
}
81+
82+
trait WSRequest extends StandaloneWSRequest {
83+
override type Self = WSRequest
84+
override def addCookies(cookies: WSCookie*): Self
85+
override def withCookies(cookie: WSCookie*): Self
86+
}
87+
}
7488

7589
object Test {
7690
def flagsString(m: java.lang.reflect.Method) = {
@@ -118,5 +132,7 @@ object Test {
118132
).foreach(show(_, m => List("head", "tail", "from").contains(m.getName())))
119133

120134
show(Class.forName("EmptyCollection"), _.getName() == "andThen")
135+
136+
show(classOf[play.WSRequest])
121137
}
122138
}

0 commit comments

Comments
 (0)