@@ -15,6 +15,7 @@ import transform.SyntheticMembers.*
15
15
import util .Property
16
16
import ast .Trees .genericEmptyTree
17
17
import annotation .{tailrec , constructorOnly }
18
+ import ast .tpd
18
19
import ast .tpd .*
19
20
import Synthesizer .*
20
21
@@ -264,10 +265,10 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
264
265
.refinedWith(tpnme.MirroredType , TypeAlias (mirroredType))
265
266
.refinedWith(tpnme.MirroredLabel , TypeAlias (ConstantType (Constant (label.toString))))
266
267
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 ))
271
272
ref.withSpan(span)
272
273
273
274
private def checkFormal (formal : Type )(using Context ): Boolean =
@@ -427,7 +428,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
427
428
.refinedWith(tpnme.MirroredElemLabels , TypeAlias (elemsLabels))
428
429
}
429
430
val mirrorRef =
430
- if cls.useCompanionAsProductMirror then companionPath(mirroredType , span)
431
+ if cls.useCompanionAsProductMirror then companionPath(pre, cls , span)
431
432
else if defn.isTupleClass(cls) then newTupleMirror(typeElems.size) // TODO: cls == defn.PairClass when > 22
432
433
else anonymousMirror(monoType, MirrorImpl .OfProduct (pre), span)
433
434
withNoErrors(mirrorRef.cast(mirrorType).withSpan(span))
@@ -437,7 +438,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
437
438
case Right (msrc) => msrc match
438
439
case MirrorSource .Singleton (_, tref) =>
439
440
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)
441
442
if tref.classSymbol.is(Scala2x ) then // could be Scala 3 alias of Scala 2 case object.
442
443
val mirrorType = formal.constrained_& {
443
444
mirrorCore(defn.Mirror_SingletonProxyClass , mirroredType, mirroredType, singleton.name)
@@ -556,7 +557,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
556
557
.refinedWith(tpnme.MirroredElemLabels , TypeAlias (labels))
557
558
}
558
559
val mirrorRef =
559
- if cls.useCompanionAsSumMirror then companionPath(mirroredType , span)
560
+ if cls.useCompanionAsSumMirror then companionPath(pre, cls , span)
560
561
else anonymousMirror(monoType, MirrorImpl .OfSum (childPres), span)
561
562
withNoErrors(mirrorRef.cast(mirrorType))
562
563
else if acceptableMsg.nonEmpty then
0 commit comments