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