From ea22e642213db5636e16012e2f7434c020756525 Mon Sep 17 00:00:00 2001 From: Matt Bovel Date: Mon, 13 Jul 2026 18:47:45 +0200 Subject: [PATCH] Remove whitebox cast from GenIso.fields Declare the honest supertype PIso[S, S, ?, ?] instead, as #1574 did for IsoFields. All match arms conform without a cast, and transparent inline still infers the precise type at call sites. This also fixes the master build, broken since #1574. Co-Authored-By: Claude Fable 5 --- .../main/scala-3/monocle/macros/GenIso.scala | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/macro/src/main/scala-3/monocle/macros/GenIso.scala b/macro/src/main/scala-3/monocle/macros/GenIso.scala index 4a930bf84..92ca33072 100644 --- a/macro/src/main/scala-3/monocle/macros/GenIso.scala +++ b/macro/src/main/scala-3/monocle/macros/GenIso.scala @@ -1,6 +1,6 @@ package monocle.macros -import monocle.Iso +import monocle.{Iso, PIso} import scala.language.`3.0` import scala.deriving.* import scala.quoted.* @@ -58,23 +58,18 @@ object GenIso { * types in the same order as the fields themselves. */ @deprecated("use monocle.Iso.fields", since = "3.1.0") - transparent inline def fields[S <: Product](using m: Mirror.ProductOf[S]): Iso[S, Any] = + transparent inline def fields[S <: Product](using m: Mirror.ProductOf[S]): PIso[S, S, ?, ?] = ${ _fields[S]('m) } - private def _fields[S <: Product](e: Expr[Mirror.ProductOf[S]])(using Quotes, Type[S]): Expr[Iso[S, Any]] = { - - def whitebox[A](e: Expr[Iso[S, A]]): Expr[Iso[S, Any]] = - e.asInstanceOf[Expr[Iso[S, Any]]] - + private def _fields[S <: Product](e: Expr[Mirror.ProductOf[S]])(using Quotes, Type[S]): Expr[PIso[S, S, ?, ?]] = e match { case '{ $m: Mirror.ProductOf[S] { type MirroredElemTypes = EmptyTuple } } => - whitebox(_unit[S](e)) + _unit[S](e) case '{ $m: Mirror.ProductOf[S] { type MirroredElemTypes = a *: EmptyTuple } } => - whitebox(_apply[S, a](e)) + _apply[S, a](e) case _ => - '{ monocle.internal.IsoFields[S](using $e) }.asInstanceOf[Expr[Iso[S, Any]]] + '{ monocle.internal.IsoFields[S](using $e) } } - } }