From 0be209c599dcbfd443b10af32484f3fcfb824cdd Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Thu, 19 Dec 2024 00:01:09 +0000 Subject: [PATCH 1/3] De-prioritize `intWitnessAs` --- .../timepit/refined/internal/WitnessAs.scala | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/modules/core/shared/src/main/scala-3.0+/eu/timepit/refined/internal/WitnessAs.scala b/modules/core/shared/src/main/scala-3.0+/eu/timepit/refined/internal/WitnessAs.scala index 39dfc0a04..c408dcfb1 100644 --- a/modules/core/shared/src/main/scala-3.0+/eu/timepit/refined/internal/WitnessAs.scala +++ b/modules/core/shared/src/main/scala-3.0+/eu/timepit/refined/internal/WitnessAs.scala @@ -25,14 +25,7 @@ import scala.compiletime.{constValue, error} final case class WitnessAs[A, B](fst: A, snd: B) object WitnessAs extends WitnessAs1 { - def apply[A, B](implicit ev: WitnessAs[A, B]): WitnessAs[A, B] = ev - - implicit def intWitnessAs[B, A <: Int](implicit - wa: ValueOf[A], - ta: ToInt[A], - nb: Numeric[B] - ): WitnessAs[A, B] = - WitnessAs(wa.value, nb.fromInt(ta.apply())) + def apply[A, B](using ev: WitnessAs[A, B]): WitnessAs[A, B] = ev inline given singletonWitnessAs[B, A <: B]: WitnessAs[A, B] = { inline val a = constValue[A] @@ -40,7 +33,7 @@ object WitnessAs extends WitnessAs1 { } } -trait WitnessAs1 { +trait WitnessAs1 extends WitnessAs2 { inline given intWitnessAsByte[A <: Int]: WitnessAs[A, Byte] = inline constValue[A] match { case a if a >= -128 && a <= 127 => WitnessAs(a, a.toByte) @@ -89,3 +82,12 @@ trait WitnessAs1 { WitnessAs(a, BigDecimal(a)) } } + +trait WitnessAs2 { + given intWitnessAs[B, A <: Int](using + wa: ValueOf[A], + ta: ToInt[A], + nb: Numeric[B] + ): WitnessAs[A, B] = + WitnessAs(wa.value, nb.fromInt(ta.apply())) +} From 0aaa91097c7b726b5408f3431fd95eb44244e1da Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Thu, 19 Dec 2024 15:57:19 +0000 Subject: [PATCH 2/3] Revert "De-prioritize `intWitnessAs`" This reverts commit 0be209c599dcbfd443b10af32484f3fcfb824cdd. --- .../timepit/refined/internal/WitnessAs.scala | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/modules/core/shared/src/main/scala-3.0+/eu/timepit/refined/internal/WitnessAs.scala b/modules/core/shared/src/main/scala-3.0+/eu/timepit/refined/internal/WitnessAs.scala index c408dcfb1..39dfc0a04 100644 --- a/modules/core/shared/src/main/scala-3.0+/eu/timepit/refined/internal/WitnessAs.scala +++ b/modules/core/shared/src/main/scala-3.0+/eu/timepit/refined/internal/WitnessAs.scala @@ -25,7 +25,14 @@ import scala.compiletime.{constValue, error} final case class WitnessAs[A, B](fst: A, snd: B) object WitnessAs extends WitnessAs1 { - def apply[A, B](using ev: WitnessAs[A, B]): WitnessAs[A, B] = ev + def apply[A, B](implicit ev: WitnessAs[A, B]): WitnessAs[A, B] = ev + + implicit def intWitnessAs[B, A <: Int](implicit + wa: ValueOf[A], + ta: ToInt[A], + nb: Numeric[B] + ): WitnessAs[A, B] = + WitnessAs(wa.value, nb.fromInt(ta.apply())) inline given singletonWitnessAs[B, A <: B]: WitnessAs[A, B] = { inline val a = constValue[A] @@ -33,7 +40,7 @@ object WitnessAs extends WitnessAs1 { } } -trait WitnessAs1 extends WitnessAs2 { +trait WitnessAs1 { inline given intWitnessAsByte[A <: Int]: WitnessAs[A, Byte] = inline constValue[A] match { case a if a >= -128 && a <= 127 => WitnessAs(a, a.toByte) @@ -82,12 +89,3 @@ trait WitnessAs1 extends WitnessAs2 { WitnessAs(a, BigDecimal(a)) } } - -trait WitnessAs2 { - given intWitnessAs[B, A <: Int](using - wa: ValueOf[A], - ta: ToInt[A], - nb: Numeric[B] - ): WitnessAs[A, B] = - WitnessAs(wa.value, nb.fromInt(ta.apply())) -} From 8e9de9f3b238673a4311e3d2d808486aa4fce5c1 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Thu, 19 Dec 2024 16:00:09 +0000 Subject: [PATCH 3/3] Deprecate generic `intWitnessAs` --- .../scala-3.0+/eu/timepit/refined/internal/WitnessAs.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/core/shared/src/main/scala-3.0+/eu/timepit/refined/internal/WitnessAs.scala b/modules/core/shared/src/main/scala-3.0+/eu/timepit/refined/internal/WitnessAs.scala index 39dfc0a04..c493042d6 100644 --- a/modules/core/shared/src/main/scala-3.0+/eu/timepit/refined/internal/WitnessAs.scala +++ b/modules/core/shared/src/main/scala-3.0+/eu/timepit/refined/internal/WitnessAs.scala @@ -27,7 +27,8 @@ final case class WitnessAs[A, B](fst: A, snd: B) object WitnessAs extends WitnessAs1 { def apply[A, B](implicit ev: WitnessAs[A, B]): WitnessAs[A, B] = ev - implicit def intWitnessAs[B, A <: Int](implicit + @deprecated("Use one of the specialized instances of intWitnessAs*", "0.11.3") + def intWitnessAs[B, A <: Int](implicit wa: ValueOf[A], ta: ToInt[A], nb: Numeric[B]