Skip to content

Commit 6c56734

Browse files
committed
handle widened module class in productMirror
1 parent 66187b1 commit 6c56734

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

compiler/src/dotty/tools/dotc/transform/SymUtils.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ object SymUtils:
9494
&& (!ctor.privateWithin.exists || isAccessible(ctor.privateWithin)) // check scope is compatible
9595

9696

97-
val companionMirror = self.useCompanionAsProductMirror
97+
def companionMirror = self.useCompanionAsProductMirror
9898
if (!self.is(CaseClass)) "it is not a case class"
9999
else if (self.is(Abstract)) "it is an abstract class"
100100
else if (self.primaryConstructor.info.paramInfoss.length != 1) "it takes more than one parameter list"

compiler/src/dotty/tools/dotc/typer/Synthesizer.scala

+5-4
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,11 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
314314
case AndType(tp1, tp2) =>
315315
orElse(productMirror(tp1, formal, span), productMirror(tp2, formal, span))
316316
case _ =>
317-
if mirroredType.termSymbol.is(CaseVal) then
318-
val module = mirroredType.termSymbol
319-
val modulePath = pathFor(mirroredType).withSpan(span)
317+
val cls = mirroredType.classSymbol
318+
if cls.isAllOf(Case | Module) then
319+
val module = cls.sourceModule
320+
val moduleRef = if mirroredType.termSymbol.exists then mirroredType else module.reachableTermRef
321+
val modulePath = pathFor(moduleRef).withSpan(span)
320322
if module.info.classSymbol.is(Scala2x) then
321323
val mirrorType = mirrorCore(defn.Mirror_SingletonProxyClass, mirroredType, mirroredType, module.name, formal)
322324
val mirrorRef = New(defn.Mirror_SingletonProxyClass.typeRef, modulePath :: Nil)
@@ -325,7 +327,6 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
325327
val mirrorType = mirrorCore(defn.Mirror_SingletonClass, mirroredType, mirroredType, module.name, formal)
326328
withNoErrors(modulePath.cast(mirrorType))
327329
else
328-
val cls = mirroredType.classSymbol
329330
val acceptableMsg = whyNotAcceptableType(mirroredType, cls)
330331
if acceptableMsg.isEmpty then
331332
if cls.isGenericProduct then makeProductMirror(cls)

0 commit comments

Comments
 (0)