Skip to content

Commit 1d5909e

Browse files
committed
Refine bringForward to work with overloaded symbols
1 parent 5bc01c2 commit 1d5909e

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

compiler/src/dotty/tools/dotc/core/Denotations.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -789,10 +789,7 @@ object Denotations {
789789
this match {
790790
case symd: SymDenotation =>
791791
if (ctx.stillValid(symd)) return updateValidity()
792-
if (ctx.acceptStale(symd)) {
793-
val newd = symd.owner.info.decls.lookup(symd.name)
794-
return (newd.denot: SingleDenotation).orElse(symd).updateValidity()
795-
}
792+
if (ctx.acceptStale(symd)) return symd.currentSymbol.denot.orElse(symd).updateValidity()
796793
case _ =>
797794
}
798795
if (!symbol.exists) return updateValidity()

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -959,7 +959,6 @@ object SymDenotations {
959959
}
960960
}
961961

962-
963962
/** The class with the same (type-) name as this module or module class,
964963
* and which is also defined in the same scope and compilation unit.
965964
* NoSymbol if this class does not exist.
@@ -1135,6 +1134,22 @@ object SymDenotations {
11351134
/** The primary constructor of a class or trait, NoSymbol if not applicable. */
11361135
def primaryConstructor(implicit ctx: Context): Symbol = NoSymbol
11371136

1137+
/** The current declaration of this symbol's class owner that has the same name
1138+
* as this one, and, if there are several, also has the same signature.
1139+
*/
1140+
def currentSymbol(implicit ctx: Context): Symbol = {
1141+
val candidates = owner.info.decls.lookupAll(name)
1142+
def test(sym: Symbol): Symbol =
1143+
if (sym == symbol || sym.signature == signature) sym
1144+
else if (candidates.hasNext) test(candidates.next)
1145+
else NoSymbol
1146+
if (candidates.hasNext) {
1147+
val sym = candidates.next
1148+
if (candidates.hasNext) test(sym) else sym
1149+
}
1150+
else NoSymbol
1151+
}
1152+
11381153
// ----- type-related ------------------------------------------------
11391154

11401155
/** The type parameters of a class symbol, Nil for all other symbols */

0 commit comments

Comments
 (0)