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())) +}