Skip to content

Commit 8b09bab

Browse files
committed
Make moduleVal/moduleClass return the current symbol when possible
This is more intuitive in my opinion. As a side-effect, this makes the logic for creating stub package symbols in `staticRef` more robust which broke the `missingDottyLib` test. This is fixed by moving the `isPackageFromCoreLibMissing` check earlier.
1 parent 3aa217f commit 8b09bab

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1301,12 +1301,12 @@ object Denotations {
13011301
if (owner.exists) {
13021302
val result = if (isPackage) owner.info.decl(selector) else owner.info.member(selector)
13031303
if (result.exists) result
1304+
else if (isPackageFromCoreLibMissing) throw new MissingCoreLibraryException(selector.toString)
13041305
else {
13051306
val alt =
13061307
if (generateStubs) missingHook(owner.symbol.moduleClass, selector)
13071308
else NoSymbol
13081309
if (alt.exists) alt.denot
1309-
else if (isPackageFromCoreLibMissing) throw new MissingCoreLibraryException(selector.toString)
13101310
else MissingRef(owner, selector)
13111311
}
13121312
}

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

Lines changed: 27 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,34 @@ 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
896+
case _ =>
897+
NoSymbol
883898
}
884-
sourceOfSelf(selfType)
885-
case info: LazyType =>
886-
info.sourceModule
887-
case _ =>
899+
else if (this is ModuleVal)
900+
symbol
901+
else
888902
NoSymbol
889-
}
890903

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ object Completion {
254254
!sym.isAbsent &&
255255
!sym.isPrimaryConstructor &&
256256
sym.sourceSymbol.exists &&
257-
(!sym.is(Package) || !sym.moduleClass.exists) &&
257+
(!sym.is(Package) || sym.is(ModuleClass)) &&
258258
!sym.is(allOf(Mutable, Accessor)) &&
259259
!sym.isPackageObject &&
260260
!sym.is(Artifact) &&

0 commit comments

Comments
 (0)