@@ -868,6 +868,13 @@ trait Implicits { self: Typer =>
868
868
.refinedWith(tpnme.MirroredMonoType , TypeAlias (monoType))
869
869
.refinedWith(tpnme.MirroredLabel , TypeAlias (ConstantType (Constant (label.toString))))
870
870
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
+
871
878
/** An implied instance for a type of the form `Mirror.Product { type MirroredMonoType = T }`
872
879
* where `T` is a generic product type or a case object or an enum case.
873
880
*/
@@ -878,16 +885,16 @@ trait Implicits { self: Typer =>
878
885
mirrorFor(tp1).orElse(mirrorFor(tp2))
879
886
case _ =>
880
887
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 )
885
893
mirrorRef.cast(mirrorType)
886
894
}
887
895
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)
891
898
}
892
899
}
893
900
else if (monoType.classSymbol.isGenericProduct) {
@@ -899,11 +906,9 @@ trait Implicits { self: Typer =>
899
906
mirrorCore(defn.Mirror_ProductType , monoType, cls.name)
900
907
.refinedWith(tpnme.MirroredElemTypes , TypeAlias (TypeOps .nestedPairs(elemTypes)))
901
908
.refinedWith(tpnme.MirroredElemLabels , TypeAlias (TypeOps .nestedPairs(elemLabels)))
902
- val modul = cls.linkedClass.sourceModule
903
- assert(modul.is(Module ))
904
909
val mirrorRef =
905
910
if (cls.is(Scala2x )) anonymousMirror(monoType, ExtendsProductMirror , span)
906
- else ref(modul).withSpan( span)
911
+ else companionPath(monoType, span)
907
912
mirrorRef.cast(mirrorType)
908
913
}
909
914
else EmptyTree
@@ -955,9 +960,8 @@ trait Implicits { self: Typer =>
955
960
val mirrorType =
956
961
mirrorCore(defn.Mirror_SumType , monoType, cls.name)
957
962
.refinedWith(tpnme.MirroredElemTypes , TypeAlias (TypeOps .nestedPairs(elemTypes)))
958
- val modul = cls.linkedClass.sourceModule
959
963
val mirrorRef =
960
- if (modul. exists && ! cls.is(Scala2x )) ref(modul).withSpan( span)
964
+ if (cls.linkedClass. exists && ! cls.is(Scala2x )) companionPath(monoType, span)
961
965
else anonymousMirror(monoType, ExtendsSumMirror , span)
962
966
mirrorRef.cast(mirrorType)
963
967
case _ =>
0 commit comments