@@ -239,7 +239,7 @@ object SymDenotations {
239
239
final def ensureCompleted ()(implicit ctx : Context ): Unit = info
240
240
241
241
/** 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.
243
243
* This method should be used only in the following circumstances:
244
244
*
245
245
* 1. When accessing type parameters or type parameter accessors (both are entered before
@@ -766,11 +766,15 @@ object SymDenotations {
766
766
* and which is also defined in the same scope and compilation unit.
767
767
* NoSymbol if this module does not exist.
768
768
*/
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
772
774
else
773
- companionNamed(effectiveName.moduleClassName).sourceModule
775
+ NoSymbol
776
+ }
777
+
774
778
775
779
/** The class with the same (type-) name as this module or module class,
776
780
* and which is also defined in the same scope and compilation unit.
@@ -781,21 +785,13 @@ object SymDenotations {
781
785
782
786
if (companionMethod.exists)
783
787
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
792
789
NoSymbol
793
- }
794
790
}
795
791
796
792
final def scalacLinkedClass (implicit ctx : Context ): Symbol =
797
793
if (this is ModuleClass ) companionNamed(effectiveName.toTypeName)
798
- else if (this .isClass) companionModule .moduleClass
794
+ else if (this .isClass) companionNamed(effectiveName.moduleClassName).sourceModule .moduleClass
799
795
else NoSymbol
800
796
801
797
0 commit comments