@@ -432,13 +432,24 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
432
432
makeProductMirror(typeElems, elemLabels, tpnme.NamedTuple , mirrorRef)
433
433
end makeNamedTupleProductMirror
434
434
435
+ def makeTupleProductMirror (tps : List [Type ]): TreeWithErrors =
436
+ val arity = tps.size
437
+ if arity < Definitions .MaxTupleArity then
438
+ val tupleCls = defn.TupleType (arity).nn.classSymbol
439
+ makeClassProductMirror(tupleCls.owner.reachableThisType, tupleCls, Some (tps))
440
+ else
441
+ val elemLabels = (for i <- 1 to arity yield ConstantType (Constant (s " _ $i" ))).toList
442
+ val mirrorRef : Type => Tree = _ => newTupleMirror(arity)
443
+ makeProductMirror(tps, elemLabels, s " Tuple $arity" .toTermName, mirrorRef)
444
+ end makeTupleProductMirror
445
+
435
446
def makeClassProductMirror (pre : Type , cls : Symbol , tps : Option [List [Type ]]) =
436
447
val accessors = cls.caseAccessors
437
448
val elemLabels = accessors.map(acc => ConstantType (Constant (acc.name.toString)))
438
449
val typeElems = tps.getOrElse(accessors.map(mirroredType.resultType.memberInfo(_).widenExpr))
439
450
val mirrorRef = (monoType : Type ) =>
440
451
if cls.useCompanionAsProductMirror then companionPath(pre, cls, span)
441
- else if defn.isTupleClass(cls) then newTupleMirror(typeElems.size) // TODO: cls == defn.PairClass when > 22
452
+ else if defn.isTupleClass(cls) then newTupleMirror(typeElems.size)
442
453
else anonymousMirror(monoType, MirrorImpl .OfProduct (pre), span)
443
454
makeProductMirror(typeElems, elemLabels, cls.name, mirrorRef)
444
455
end makeClassProductMirror
@@ -478,14 +489,7 @@ class Synthesizer(typer: Typer)(using @constructorOnly c: Context):
478
489
}
479
490
withNoErrors(singletonPath.cast(mirrorType).withSpan(span))
480
491
case MirrorSource .GenericTuple (tps) =>
481
- val maxArity = Definitions .MaxTupleArity
482
- val arity = tps.size
483
- if tps.size <= maxArity then
484
- val tupleCls = defn.TupleType (arity).nn.classSymbol
485
- makeClassProductMirror(tupleCls.owner.reachableThisType, tupleCls, Some (tps))
486
- else
487
- val reason = s " it reduces to a tuple with arity $arity, expected arity <= $maxArity"
488
- withErrors(i " ${defn.PairClass } is not a generic product because $reason" )
492
+ makeTupleProductMirror(tps)
489
493
case MirrorSource .NamedTuple (nameTypePairs) =>
490
494
makeNamedTupleProductMirror(nameTypePairs)
491
495
case MirrorSource .ClassSymbol (pre, cls) =>
0 commit comments