@@ -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 .*
2021
@@ -264,10 +265,10 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
264265 .refinedWith(tpnme.MirroredType , TypeAlias (mirroredType))
265266 .refinedWith(tpnme.MirroredLabel , TypeAlias (ConstantType (Constant (label.toString))))
266267
267- /** A path referencing the companion of class type `clsType ` */
268- private def companionPath (clsType : Type , span : Span )(using Context ) =
269- val ref = pathFor(clsType.mirrorCompanionRef )
270- assert(ref.symbol.is(Module ) && (clsType.classSymbol. is(ModuleClass ) || ( ref.symbol.companionClass == clsType.classSymbol) ))
268+ /** A path referencing the companion of `cls` with prefix `pre ` */
269+ private def companionPath (pre : Type , cls : Symbol , span : Span )(using Context ) =
270+ val ref = tpd.ref( TermRef (pre, cls.companionModule) )
271+ assert(ref.symbol.is(Module ) && (cls. is(ModuleClass ) || ref.symbol.companionClass == cls ))
271272 ref.withSpan(span)
272273
273274 private def checkFormal (formal : Type )(using Context ): Boolean =
@@ -427,7 +428,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
427428 .refinedWith(tpnme.MirroredElemLabels , TypeAlias (elemsLabels))
428429 }
429430 val mirrorRef =
430- if cls.useCompanionAsProductMirror then companionPath(mirroredType , span)
431+ if cls.useCompanionAsProductMirror then companionPath(pre, cls , span)
431432 else if defn.isTupleClass(cls) then newTupleMirror(typeElems.size) // TODO: cls == defn.PairClass when > 22
432433 else anonymousMirror(monoType, MirrorImpl .OfProduct (pre), span)
433434 withNoErrors(mirrorRef.cast(mirrorType).withSpan(span))
@@ -437,7 +438,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
437438 case Right (msrc) => msrc match
438439 case MirrorSource .Singleton (_, tref) =>
439440 val singleton = tref.termSymbol // prefer alias name over the orignal name
440- val singletonPath = pathFor (tref).withSpan(span)
441+ val singletonPath = tpd.singleton (tref).withSpan(span)
441442 if tref.classSymbol.is(Scala2x ) then // could be Scala 3 alias of Scala 2 case object.
442443 val mirrorType = formal.constrained_& {
443444 mirrorCore(defn.Mirror_SingletonProxyClass , mirroredType, mirroredType, singleton.name)
@@ -556,7 +557,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
556557 .refinedWith(tpnme.MirroredElemLabels , TypeAlias (labels))
557558 }
558559 val mirrorRef =
559- if cls.useCompanionAsSumMirror then companionPath(mirroredType , span)
560+ if cls.useCompanionAsSumMirror then companionPath(pre, cls , span)
560561 else anonymousMirror(monoType, MirrorImpl .OfSum (childPres), span)
561562 withNoErrors(mirrorRef.cast(mirrorType))
562563 else if acceptableMsg.nonEmpty then
0 commit comments