Skip to content

Commit 368fe8d

Browse files
committed
Make moduleVal/moduleClass return the current symbol when possible
1 parent 3aa217f commit 368fe8d

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

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

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -852,13 +852,17 @@ object SymDenotations {
852852
* During completion, references to moduleClass and sourceModules are stored in
853853
* the completers.
854854
*/
855-
/** The class implementing this module, NoSymbol if not applicable. */
855+
/** If this a module class, return itself, if this is a module, the corresponding class,
856+
* otherwise NoSymbol
857+
*/
856858
final def moduleClass(implicit ctx: Context): Symbol = {
857859
def notFound = {
858860
if (Config.showCompletions) println(s"missing module class for $name: $myInfo")
859861
NoSymbol
860862
}
861-
if (this is ModuleVal)
863+
if (this is ModuleClass)
864+
symbol
865+
else if (this is ModuleVal)
862866
myInfo match {
863867
case info: TypeRef => info.symbol
864868
case ExprType(info: TypeRef) => info.symbol // needed after uncurry, when module terms might be accessor defs
@@ -873,20 +877,26 @@ object SymDenotations {
873877
else NoSymbol
874878
}
875879

876-
/** The module implemented by this module class, NoSymbol if not applicable. */
877-
final def sourceModule(implicit ctx: Context): Symbol = myInfo match {
878-
case ClassInfo(_, _, _, _, selfType) if this is ModuleClass =>
879-
def sourceOfSelf(tp: TypeOrSymbol): Symbol = tp match {
880-
case tp: TermRef => tp.symbol
881-
case tp: Symbol => sourceOfSelf(tp.info)
882-
case tp: RefinedType => sourceOfSelf(tp.parent)
880+
/** If this a module, return itself, if this is a module class, the corresponding module,
881+
* otherwise NoSymbol
882+
*/
883+
final def sourceModule(implicit ctx: Context): Symbol =
884+
if (this is ModuleVal)
885+
symbol
886+
else
887+
myInfo match {
888+
case ClassInfo(_, _, _, _, selfType) if this is ModuleClass =>
889+
def sourceOfSelf(tp: TypeOrSymbol): Symbol = tp match {
890+
case tp: TermRef => tp.symbol
891+
case tp: Symbol => sourceOfSelf(tp.info)
892+
case tp: RefinedType => sourceOfSelf(tp.parent)
893+
}
894+
sourceOfSelf(selfType)
895+
case info: LazyType =>
896+
info.sourceModule
897+
case _ =>
898+
NoSymbol
883899
}
884-
sourceOfSelf(selfType)
885-
case info: LazyType =>
886-
info.sourceModule
887-
case _ =>
888-
NoSymbol
889-
}
890900

891901
/** The field accessed by this getter or setter, or if it does not exist, the getter */
892902
def accessedFieldOrGetter(implicit ctx: Context): Symbol = {

0 commit comments

Comments
 (0)