@@ -868,6 +868,13 @@ trait Implicits { self: Typer =>
868868 .refinedWith(tpnme.MirroredMonoType , TypeAlias (monoType))
869869 .refinedWith(tpnme.MirroredLabel , TypeAlias (ConstantType (Constant (label.toString))))
870870
871+ /** A path referencing the companion of class type `clsType` */
872+ private def companionPath (clsType : Type , span : Span )(implicit ctx : Context ) = {
873+ val ref = pathFor(clsType.companionRef)
874+ assert(ref.symbol.is(Module ) && ref.symbol.companionClass == clsType.classSymbol)
875+ ref.withSpan(span)
876+ }
877+
871878 /** An implied instance for a type of the form `Mirror.Product { type MirroredMonoType = T }`
872879 * where `T` is a generic product type or a case object or an enum case.
873880 */
@@ -878,16 +885,16 @@ trait Implicits { self: Typer =>
878885 mirrorFor(tp1).orElse(mirrorFor(tp2))
879886 case _ =>
880887 if (monoType.termSymbol.is(CaseVal )) {
881- val modul = monoType.termSymbol
882- if (modul.info.classSymbol.is(Scala2x )) {
883- val mirrorType = mirrorCore(defn.Mirror_SingletonProxyType , monoType, modul.name)
884- val mirrorRef = New (defn.Mirror_SingletonProxyType , ref(modul).withSpan(span) :: Nil )
888+ val module = monoType.termSymbol
889+ val modulePath = pathFor(monoType).withSpan(span)
890+ if (module.info.classSymbol.is(Scala2x )) {
891+ val mirrorType = mirrorCore(defn.Mirror_SingletonProxyType , monoType, module.name)
892+ val mirrorRef = New (defn.Mirror_SingletonProxyType , modulePath :: Nil )
885893 mirrorRef.cast(mirrorType)
886894 }
887895 else {
888- val mirrorType = mirrorCore(defn.Mirror_SingletonType , monoType, modul.name)
889- val mirrorRef = ref(modul).withSpan(span)
890- mirrorRef.cast(mirrorType)
896+ val mirrorType = mirrorCore(defn.Mirror_SingletonType , monoType, module.name)
897+ modulePath.cast(mirrorType)
891898 }
892899 }
893900 else if (monoType.classSymbol.isGenericProduct) {
@@ -899,11 +906,9 @@ trait Implicits { self: Typer =>
899906 mirrorCore(defn.Mirror_ProductType , monoType, cls.name)
900907 .refinedWith(tpnme.MirroredElemTypes , TypeAlias (TypeOps .nestedPairs(elemTypes)))
901908 .refinedWith(tpnme.MirroredElemLabels , TypeAlias (TypeOps .nestedPairs(elemLabels)))
902- val modul = cls.linkedClass.sourceModule
903- assert(modul.is(Module ))
904909 val mirrorRef =
905910 if (cls.is(Scala2x )) anonymousMirror(monoType, ExtendsProductMirror , span)
906- else ref(modul).withSpan( span)
911+ else companionPath(monoType, span)
907912 mirrorRef.cast(mirrorType)
908913 }
909914 else EmptyTree
@@ -955,9 +960,8 @@ trait Implicits { self: Typer =>
955960 val mirrorType =
956961 mirrorCore(defn.Mirror_SumType , monoType, cls.name)
957962 .refinedWith(tpnme.MirroredElemTypes , TypeAlias (TypeOps .nestedPairs(elemTypes)))
958- val modul = cls.linkedClass.sourceModule
959963 val mirrorRef =
960- if (modul. exists && ! cls.is(Scala2x )) ref(modul).withSpan( span)
964+ if (cls.linkedClass. exists && ! cls.is(Scala2x )) companionPath(monoType, span)
961965 else anonymousMirror(monoType, ExtendsSumMirror , span)
962966 mirrorRef.cast(mirrorType)
963967 case _ =>
0 commit comments