@@ -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
import sbt .ExtractDependencies .*
@@ -265,10 +266,10 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
265
266
.refinedWith(tpnme.MirroredType , TypeAlias (mirroredType))
266
267
.refinedWith(tpnme.MirroredLabel , TypeAlias (ConstantType (Constant (label.toString))))
267
268
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 ))
272
273
ref.withSpan(span)
273
274
274
275
private def checkFormal (formal : Type )(using Context ): Boolean =
@@ -428,7 +429,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
428
429
.refinedWith(tpnme.MirroredElemLabels , TypeAlias (elemsLabels))
429
430
}
430
431
val mirrorRef =
431
- if cls.useCompanionAsProductMirror then companionPath(mirroredType , span)
432
+ if cls.useCompanionAsProductMirror then companionPath(pre, cls , span)
432
433
else if defn.isTupleClass(cls) then newTupleMirror(typeElems.size) // TODO: cls == defn.PairClass when > 22
433
434
else anonymousMirror(monoType, MirrorImpl .OfProduct (pre), span)
434
435
withNoErrors(mirrorRef.cast(mirrorType).withSpan(span))
@@ -438,7 +439,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
438
439
case Right (msrc) => msrc match
439
440
case MirrorSource .Singleton (_, tref) =>
440
441
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)
442
443
if tref.classSymbol.is(Scala2x ) then // could be Scala 3 alias of Scala 2 case object.
443
444
val mirrorType = formal.constrained_& {
444
445
mirrorCore(defn.Mirror_SingletonProxyClass , mirroredType, mirroredType, singleton.name)
@@ -571,7 +572,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
571
572
.refinedWith(tpnme.MirroredElemLabels , TypeAlias (labels))
572
573
}
573
574
val mirrorRef =
574
- if cls.useCompanionAsSumMirror then companionPath(mirroredType , span)
575
+ if cls.useCompanionAsSumMirror then companionPath(pre, cls , span)
575
576
else anonymousMirror(monoType, MirrorImpl .OfSum (childPres), span)
576
577
withNoErrors(mirrorRef.cast(mirrorType))
577
578
else if acceptableMsg.nonEmpty then
0 commit comments