@@ -103,7 +103,7 @@ object Expr {
103
103
case 20 => ofTupleFromSeq20(seq)
104
104
case 21 => ofTupleFromSeq21(seq)
105
105
case 22 => ofTupleFromSeq22(seq)
106
- case _ => ' { Tuple .fromIArray( IArray ( $ { Varargs ( seq)} : _* )) }
106
+ case _ => ofTupleFromSeqXXL( seq)
107
107
}
108
108
}
109
109
@@ -214,6 +214,19 @@ object Expr {
214
214
case Seq (' { $x1 : t1 }, ' { $x2 : t2 }, ' { $x3 : t3 }, ' { $x4 : t4 }, ' { $x5 : t5 }, ' { $x6 : t6 }, ' { $x7 : t7 }, ' { $x8 : t8 }, ' { $x9 : t9 }, ' { $x10 : t10 }, ' { $x11 : t11 }, ' { $x12 : t12 }, ' { $x13 : t13 }, ' { $x14 : t14 }, ' { $x15 : t15 }, ' { $x16 : t16 }, ' { $x17 : t17 }, ' { $x18 : t18 }, ' { $x19 : t19 }, ' { $x20 : t20 }, ' { $x21 : t21 }, ' { $x22 : t22 }) =>
215
215
' { Tuple22 ($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19, $x20, $x21, $x22) }
216
216
217
+ private def ofTupleFromSeqXXL (seq : Seq [Expr [Any ]])(using Quotes ): Expr [Tuple ] =
218
+ val tupleTpe = tupleTypeFromSeq(seq)
219
+ tupleTpe.asType match
220
+ case ' [tpe] =>
221
+ ' { Tuple .fromIArray(IArray ($ {Varargs (seq)}: _* )).asInstanceOf [tpe & Tuple ] }
222
+
223
+ private def tupleTypeFromSeq (seq : Seq [Expr [Any ]])(using Quotes ): quotes.reflect.TypeRepr =
224
+ import quotes .reflect .*
225
+ val consRef = Symbol .classSymbol(" scala.*:" ).typeRef
226
+ seq.foldLeft(TypeRepr .of[EmptyTuple ]) { (ts, expr) =>
227
+ expr match
228
+ case ' { $e : t } => AppliedType (consRef, TypeRepr .of[t] :: ts :: Nil )
229
+ }
217
230
218
231
/** Given a tuple of the form `(Expr[A1], ..., Expr[An])`, outputs a tuple `Expr[(A1, ..., An)]`. */
219
232
def ofTuple [T <: Tuple : Tuple .IsMappedBy [Expr ]: Type ](tup : T )(using Quotes ): Expr [Tuple .InverseMap [T , Expr ]] = {
0 commit comments