Skip to content

Commit f9910eb

Browse files
committed
Use methods to find companion modules
1 parent 595c3f6 commit f9910eb

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ object SymDenotations {
239239
final def ensureCompleted()(implicit ctx: Context): Unit = info
240240

241241
/** The symbols defined in this class or object.
242-
* Careful! This coes not force the type, so is compilation order dependent.
242+
* Careful! This does not force the type, so is compilation order dependent.
243243
* This method should be used only in the following circumstances:
244244
*
245245
* 1. When accessing type parameters or type parameter accessors (both are entered before
@@ -766,11 +766,15 @@ object SymDenotations {
766766
* and which is also defined in the same scope and compilation unit.
767767
* NoSymbol if this module does not exist.
768768
*/
769-
final def companionModule(implicit ctx: Context): Symbol =
770-
if (name == tpnme.ANON_CLASS)
771-
NoSymbol // avoid forcing anon classes, this might cause cyclic reference errors
769+
final def companionModule(implicit ctx: Context): Symbol = {
770+
val companionMethod = info.decls.denotsNamed(nme.COMPANION_MODULE_METHOD, selectPrivate).first
771+
772+
if (companionMethod.exists)
773+
companionMethod.info.resultType.classSymbol.sourceModule
772774
else
773-
companionNamed(effectiveName.moduleClassName).sourceModule
775+
NoSymbol
776+
}
777+
774778

775779
/** The class with the same (type-) name as this module or module class,
776780
* and which is also defined in the same scope and compilation unit.
@@ -781,21 +785,13 @@ object SymDenotations {
781785

782786
if (companionMethod.exists)
783787
companionMethod.info.resultType.classSymbol
784-
else {
785-
/*
786-
val scalac = companionNamed(effectiveName.toTypeName)
787-
788-
if (scalac.exists) {
789-
println(s"scalac returned companion class for $this to be $scalac")
790-
}
791-
*/
788+
else
792789
NoSymbol
793-
}
794790
}
795791

796792
final def scalacLinkedClass(implicit ctx: Context): Symbol =
797793
if (this is ModuleClass) companionNamed(effectiveName.toTypeName)
798-
else if (this.isClass) companionModule.moduleClass
794+
else if (this.isClass) companionNamed(effectiveName.moduleClassName).sourceModule.moduleClass
799795
else NoSymbol
800796

801797

src/dotty/tools/dotc/core/SymbolLoaders.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ abstract class SymbolLoader extends LazyType {
217217
denot.markAbsent()
218218
postProcess(root)
219219
if (!root.isRoot)
220-
postProcess(root.linkedClass.denot)
220+
postProcess(root.scalacLinkedClass.denot)
221221
}
222222
}
223223
}

0 commit comments

Comments
 (0)