Skip to content

Commit 637dc63

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

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

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

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,9 @@ 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, return the corresponding class, if this is a module, return itself,
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")
@@ -870,23 +872,32 @@ object SymDenotations {
870872
}
871873
case _ => notFound
872874
}
873-
else NoSymbol
875+
else if (this is ModuleClass)
876+
symbol
877+
else
878+
NoSymbol
874879
}
875880

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)
881+
/** If this a module class, return the corresponding module, if this is a module, return itself,
882+
* otherwise NoSymbol
883+
*/
884+
final def sourceModule(implicit ctx: Context): Symbol =
885+
if (this is ModuleClass)
886+
myInfo match {
887+
case ClassInfo(_, _, _, _, selfType) =>
888+
def sourceOfSelf(tp: TypeOrSymbol): Symbol = tp match {
889+
case tp: TermRef => tp.symbol
890+
case tp: Symbol => sourceOfSelf(tp.info)
891+
case tp: RefinedType => sourceOfSelf(tp.parent)
892+
}
893+
sourceOfSelf(selfType)
894+
case info: LazyType =>
895+
info.sourceModule
883896
}
884-
sourceOfSelf(selfType)
885-
case info: LazyType =>
886-
info.sourceModule
887-
case _ =>
897+
else if (this is ModuleVal)
898+
symbol
899+
else
888900
NoSymbol
889-
}
890901

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

0 commit comments

Comments
 (0)