Skip to content

Commit 052764b

Browse files
committed
Refine bringForward to work with overloaded symbols
1 parent b31333c commit 052764b

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
@@ -958,7 +958,6 @@ object SymDenotations {
958958
}
959959
}
960960

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

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

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

0 commit comments

Comments
 (0)