@@ -824,6 +824,13 @@ trait Implicits { self: Typer =>
824824 .refinedWith(tpnme.MirroredMonoType , TypeAlias (monoType))
825825 .refinedWith(tpnme.MirroredLabel , TypeAlias (ConstantType (Constant (label.toString))))
826826
827+ /** A path referencing the companion of class type `clsType` */
828+ private def companionPath (clsType : Type , span : Span )(implicit ctx : Context ) = {
829+ val ref = pathFor(clsType.companionRef)
830+ assert(ref.symbol.is(Module ) && ref.symbol.companionClass == clsType.classSymbol)
831+ ref.withSpan(span)
832+ }
833+
827834 /** An implied instance for a type of the form `Mirror.Product { type MirroredMonoType = T }`
828835 * where `T` is a generic product type or a case object or an enum case.
829836 */
@@ -834,16 +841,16 @@ trait Implicits { self: Typer =>
834841 mirrorFor(tp1).orElse(mirrorFor(tp2))
835842 case _ =>
836843 if (monoType.termSymbol.is(CaseVal )) {
837- val modul = monoType.termSymbol
838- if (modul.info.classSymbol.is(Scala2x )) {
839- val mirrorType = mirrorCore(defn.Mirror_SingletonProxyType , monoType, modul.name)
840- val mirrorRef = New (defn.Mirror_SingletonProxyType , ref(modul).withSpan(span) :: Nil )
844+ val module = monoType.termSymbol
845+ val modulePath = pathFor(monoType).withSpan(span)
846+ if (module.info.classSymbol.is(Scala2x )) {
847+ val mirrorType = mirrorCore(defn.Mirror_SingletonProxyType , monoType, module.name)
848+ val mirrorRef = New (defn.Mirror_SingletonProxyType , modulePath :: Nil )
841849 mirrorRef.cast(mirrorType)
842850 }
843851 else {
844- val mirrorType = mirrorCore(defn.Mirror_SingletonType , monoType, modul.name)
845- val mirrorRef = ref(modul).withSpan(span)
846- mirrorRef.cast(mirrorType)
852+ val mirrorType = mirrorCore(defn.Mirror_SingletonType , monoType, module.name)
853+ modulePath.cast(mirrorType)
847854 }
848855 }
849856 else if (monoType.classSymbol.isGenericProduct) {
@@ -855,11 +862,9 @@ trait Implicits { self: Typer =>
855862 mirrorCore(defn.Mirror_ProductType , monoType, cls.name)
856863 .refinedWith(tpnme.MirroredElemTypes , TypeAlias (TypeOps .nestedPairs(elemTypes)))
857864 .refinedWith(tpnme.MirroredElemLabels , TypeAlias (TypeOps .nestedPairs(elemLabels)))
858- val modul = cls.linkedClass.sourceModule
859- assert(modul.is(Module ))
860865 val mirrorRef =
861866 if (cls.is(Scala2x )) anonymousMirror(monoType, ExtendsProductMirror , span)
862- else ref(modul).withSpan( span)
867+ else companionPath(monoType, span)
863868 mirrorRef.cast(mirrorType)
864869 }
865870 else EmptyTree
@@ -911,9 +916,8 @@ trait Implicits { self: Typer =>
911916 val mirrorType =
912917 mirrorCore(defn.Mirror_SumType , monoType, cls.name)
913918 .refinedWith(tpnme.MirroredElemTypes , TypeAlias (TypeOps .nestedPairs(elemTypes)))
914- val modul = cls.linkedClass.sourceModule
915919 val mirrorRef =
916- if (modul. exists && ! cls.is(Scala2x )) ref(modul).withSpan( span)
920+ if (cls.linkedClass. exists && ! cls.is(Scala2x )) companionPath(monoType, span)
917921 else anonymousMirror(monoType, ExtendsSumMirror , span)
918922 mirrorRef.cast(mirrorType)
919923 case _ =>
0 commit comments