@@ -310,22 +310,31 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
310
310
withNoErrors(mirrorRef.cast(mirrorType))
311
311
end makeProductMirror
312
312
313
+ /** widen TermRef to see if they are an alias to an enum singleton */
314
+ def isEnumSingletonRef (tp : Type )(using Context ): Boolean = tp match
315
+ case tp : TermRef =>
316
+ val sym = tp.termSymbol
317
+ sym.isEnumCase || (! tp.isOverloaded && isEnumSingletonRef(tp.underlying.widenExpr))
318
+ case _ => false
319
+
313
320
mirroredType match
314
321
case AndType (tp1, tp2) =>
315
322
orElse(productMirror(tp1, formal, span), productMirror(tp2, formal, span))
316
323
case _ =>
317
- if mirroredType.termSymbol.is(CaseVal ) then
318
- val module = mirroredType.termSymbol
319
- val modulePath = pathFor(mirroredType).withSpan(span)
320
- if module.info.classSymbol.is(Scala2x ) then
321
- val mirrorType = mirrorCore(defn.Mirror_SingletonProxyClass , mirroredType, mirroredType, module.name, formal)
322
- val mirrorRef = New (defn.Mirror_SingletonProxyClass .typeRef, modulePath :: Nil )
324
+ val cls = mirroredType.classSymbol
325
+ if isEnumSingletonRef(mirroredType) || cls.isAllOf(Case | Module ) then
326
+ val (singleton, singletonRef) =
327
+ if mirroredType.termSymbol.exists then (mirroredType.termSymbol, mirroredType)
328
+ else (cls.sourceModule, cls.sourceModule.reachableTermRef)
329
+ val singletonPath = pathFor(singletonRef).withSpan(span)
330
+ if singleton.info.classSymbol.is(Scala2x ) then // could be Scala 3 alias of Scala 2 case object.
331
+ val mirrorType = mirrorCore(defn.Mirror_SingletonProxyClass , mirroredType, mirroredType, singleton.name, formal)
332
+ val mirrorRef = New (defn.Mirror_SingletonProxyClass .typeRef, singletonPath :: Nil )
323
333
withNoErrors(mirrorRef.cast(mirrorType))
324
334
else
325
- val mirrorType = mirrorCore(defn.Mirror_SingletonClass , mirroredType, mirroredType, module .name, formal)
326
- withNoErrors(modulePath .cast(mirrorType))
335
+ val mirrorType = mirrorCore(defn.Mirror_SingletonClass , mirroredType, mirroredType, singleton .name, formal)
336
+ withNoErrors(singletonPath .cast(mirrorType))
327
337
else
328
- val cls = mirroredType.classSymbol
329
338
val acceptableMsg = whyNotAcceptableType(mirroredType, cls)
330
339
if acceptableMsg.isEmpty then
331
340
if cls.isGenericProduct then makeProductMirror(cls)
0 commit comments