Skip to content

Commit fc6c2af

Browse files
committed
Bring matchSymbol in line with sourceSymbol
1 parent 21bec7b commit fc6c2af

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

compiler/src/dotty/tools/dotc/interactive/Interactive.scala

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ object Interactive {
6262
sourceSymbol(sym.owner)
6363
else sym
6464

65+
/** Check if `tree` matches `sym`.
66+
* This is the case if the symbol defined by `tree` equals `sym`,
67+
* or the source symbol of tree equals sym,
68+
* or `includeOverridden is true, and `sym` is overriden by `tree`.
69+
*/
70+
def matchSymbol(tree: Tree, sym: Symbol, includeOverridden: Boolean)(implicit ctx: Context): Boolean =
71+
( sym == tree.symbol
72+
|| sym.exists && sym == sourceSymbol(tree.symbol)
73+
|| includeOverridden && sym.name == tree.symbol.name &&
74+
tree.symbol.owner.derivesFrom(sym.owner) && tree.symbol.overriddenSymbol(sym.owner.asClass) == sym
75+
)
76+
6577
private def safely[T](op: => List[T]): List[T] =
6678
try op catch { case ex: TypeError => Nil }
6779

@@ -175,19 +187,6 @@ object Interactive {
175187
buf.toList
176188
}
177189

178-
/** Check if `tree` matches `sym`.
179-
* This is the case if one of the following is true:
180-
* (1) `sym` is the symbol of `tree`, or
181-
* (2) `sym` is a module value and its module class matches, or
182-
* (3) `includeOverridden is true, and `sym` is overriden by `tree`.
183-
*/
184-
def matchSymbol(tree: Tree, sym: Symbol, includeOverridden: Boolean)(implicit ctx: Context): Boolean =
185-
( sym == tree.symbol
186-
|| sym.is(ModuleVal) && tree.symbol == sym.moduleClass
187-
|| includeOverridden && sym.name == tree.symbol.name && sym.owner.isClass &&
188-
tree.symbol.overriddenSymbol(sym.owner.asClass) == sym
189-
)
190-
191190
/** The reverse path to the node that closest encloses position `pos`,
192191
* or `Nil` if no such path exists. If a non-empty path is returned it starts with
193192
* the tree closest enclosing `pos` and ends with an element of `trees`.

0 commit comments

Comments
 (0)