@@ -15,6 +15,7 @@ import transform.SyntheticMembers.*
1515import util .Property
1616import ast .Trees .genericEmptyTree
1717import annotation .{tailrec , constructorOnly }
18+ import ast .tpd
1819import ast .tpd .*
1920import Synthesizer .*
2021import sbt .ExtractDependencies .*
@@ -265,10 +266,10 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
265266 .refinedWith(tpnme.MirroredType , TypeAlias (mirroredType))
266267 .refinedWith(tpnme.MirroredLabel , TypeAlias (ConstantType (Constant (label.toString))))
267268
268- /** A path referencing the companion of class type `clsType ` */
269- private def companionPath (clsType : Type , span : Span )(using Context ) =
270- val ref = pathFor(clsType.mirrorCompanionRef )
271- assert(ref.symbol.is(Module ) && (clsType.classSymbol. is(ModuleClass ) || ( ref.symbol.companionClass == clsType.classSymbol) ))
269+ /** A path referencing the companion of `cls` with prefix `pre ` */
270+ private def companionPath (pre : Type , cls : Symbol , span : Span )(using Context ) =
271+ val ref = tpd.ref( TermRef (pre, cls.companionModule) )
272+ assert(ref.symbol.is(Module ) && (cls. is(ModuleClass ) || ref.symbol.companionClass == cls ))
272273 ref.withSpan(span)
273274
274275 private def checkFormal (formal : Type )(using Context ): Boolean =
@@ -428,7 +429,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
428429 .refinedWith(tpnme.MirroredElemLabels , TypeAlias (elemsLabels))
429430 }
430431 val mirrorRef =
431- if cls.useCompanionAsProductMirror then companionPath(mirroredType , span)
432+ if cls.useCompanionAsProductMirror then companionPath(pre, cls , span)
432433 else if defn.isTupleClass(cls) then newTupleMirror(typeElems.size) // TODO: cls == defn.PairClass when > 22
433434 else anonymousMirror(monoType, MirrorImpl .OfProduct (pre), span)
434435 withNoErrors(mirrorRef.cast(mirrorType).withSpan(span))
@@ -438,7 +439,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
438439 case Right (msrc) => msrc match
439440 case MirrorSource .Singleton (_, tref) =>
440441 val singleton = tref.termSymbol // prefer alias name over the orignal name
441- val singletonPath = pathFor (tref).withSpan(span)
442+ val singletonPath = tpd.singleton (tref).withSpan(span)
442443 if tref.classSymbol.is(Scala2x ) then // could be Scala 3 alias of Scala 2 case object.
443444 val mirrorType = formal.constrained_& {
444445 mirrorCore(defn.Mirror_SingletonProxyClass , mirroredType, mirroredType, singleton.name)
@@ -571,7 +572,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
571572 .refinedWith(tpnme.MirroredElemLabels , TypeAlias (labels))
572573 }
573574 val mirrorRef =
574- if cls.useCompanionAsSumMirror then companionPath(mirroredType , span)
575+ if cls.useCompanionAsSumMirror then companionPath(pre, cls , span)
575576 else anonymousMirror(monoType, MirrorImpl .OfSum (childPres), span)
576577 withNoErrors(mirrorRef.cast(mirrorType))
577578 else if acceptableMsg.nonEmpty then
0 commit comments