@@ -407,6 +407,12 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
407
407
def newTupleMirror (arity : Int ): Tree =
408
408
New (defn.RuntimeTupleMirrorTypeRef , Literal (Constant (arity)) :: Nil )
409
409
410
+ def newJavaRecordReflectMirror (tpe : Type ) =
411
+ ref(defn.JavaRecordReflectMirrorModule )
412
+ .select(nme.apply)
413
+ .appliedToType(tpe)
414
+ .appliedTo(clsOf(tpe))
415
+
410
416
def makeProductMirror (pre : Type , cls : Symbol , tps : Option [List [Type ]]): TreeWithErrors =
411
417
val accessors = cls.caseAccessors
412
418
val elemLabels = accessors.map(acc => ConstantType (Constant (acc.name.toString)))
@@ -427,6 +433,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
427
433
}
428
434
val mirrorRef =
429
435
if cls.useCompanionAsProductMirror then companionPath(mirroredType, span)
436
+ else if defn.isJavaRecordClass(cls) then newJavaRecordReflectMirror(cls.typeRef)
430
437
else if defn.isTupleClass(cls) then newTupleMirror(typeElems.size) // TODO: cls == defn.PairClass when > 22
431
438
else anonymousMirror(monoType, MirrorImpl .OfProduct (pre), span)
432
439
withNoErrors(mirrorRef.cast(mirrorType).withSpan(span))
@@ -458,14 +465,17 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
458
465
val reason = s " it reduces to a tuple with arity $arity, expected arity <= $maxArity"
459
466
withErrors(i " ${defn.PairClass } is not a generic product because $reason" )
460
467
case MirrorSource .ClassSymbol (pre, cls) =>
468
+
461
469
if cls.isGenericProduct then
462
470
if ctx.runZincPhases then
463
471
// The mirror should be resynthesized if the constructor of the
464
472
// case class `cls` changes. See `sbt-test/source-dependencies/mirror-product`.
465
473
val rec = ctx.compilationUnit.depRecorder
466
474
rec.addClassDependency(cls, DependencyByMemberRef )
467
475
rec.addUsedName(cls.primaryConstructor)
468
- makeProductMirror(pre, cls, None )
476
+ val stuff = makeProductMirror(pre, cls, None )
477
+ println(stuff._1.show)
478
+ stuff
469
479
else withErrors(i " $cls is not a generic product because ${cls.whyNotGenericProduct}" )
470
480
case Left (msg) =>
471
481
withErrors(i " type ` $mirroredType` is not a generic product because $msg" )
0 commit comments