@@ -49,15 +49,16 @@ given derived[T: Type](using Quotes): Expr[Eq[T]] =
4949 ev match
5050 case ' { $m : Mirror .ProductOf [T ] { type MirroredElemTypes = elementTypes }} =>
5151 val elemInstances = summonAll[elementTypes]
52- val eqProductBody : (Expr [T ], Expr [T ]) => Expr [Boolean ] = (x, y) =>
53- elemInstances.zipWithIndex.foldLeft(Expr (true : Boolean )) {
54- case (acc, (elem, index)) =>
55- val e1 = ' {$x.asInstanceOf [Product ].productElement($ {Expr (index)})}
56- val e2 = ' {$y.asInstanceOf [Product ].productElement($ {Expr (index)})}
57- ' { $acc && $elem.asInstanceOf [Eq [Any ]].eqv($e1, $e2) }
58- }
59-
60- ' { eqProduct((x : T , y : T ) => $ {eqProductBody(' x , ' y )}) }
52+ def eqProductBody (x : Expr [Product ], y : Expr [Product ])(using Quotes ): Expr [Boolean ] = {
53+ elemInstances.zipWithIndex.foldLeft(Expr (true )) {
54+ case (acc, (' { $elem : Eq [t] }, index)) =>
55+ val indexExpr = Expr (index)
56+ val e1 = ' { $x.productElement($indexExpr).asInstanceOf [t] }
57+ val e2 = ' { $y.productElement($indexExpr).asInstanceOf [t] }
58+ ' { $acc && $elem.eqv($e1, $e2) }
59+ }
60+ }
61+ ' { eqProduct((x : T , y : T ) => $ {eqProductBody(' x .asExprOf[Product ], ' y .asExprOf[Product ])}) }
6162
6263 // case for Mirror.ProductOf[T]
6364 // ...
0 commit comments