Skip to content

Commit e728655

Browse files
committed
change toString for BigDecimal
1 parent 0afa50d commit e728655

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

library/src/scala/math/BigDecimal.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,6 @@ extends ScalaNumber with ScalaNumericConversions with Serializable with Ordered[
717717

718718
/** Returns the decimal String representation of this BigDecimal.
719719
*/
720-
override def toString: String = this.bigDecimal.toString
720+
override def toString(): String = this.bigDecimal.toString
721721

722722
}

tests/warn/i24093.check

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- [E197] Potential Issue Warning: tests/warn/i24093.scala:18:10 ---------------
2+
18 | new StringConverter[T]:
3+
| ^
4+
| New anonymous class definition will be duplicated at each inline site
5+
|
6+
| longer explanation available when compiling with `-explain`
7+
-- [E197] Potential Issue Warning: tests/warn/i24093.scala:34:4 ----------------
8+
34 | new QueryParamsConverter[T] {
9+
| ^
10+
| New anonymous class definition will be duplicated at each inline site
11+
|
12+
| longer explanation available when compiling with `-explain`

tests/warn/i24093.scala

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import scala.deriving.*
2+
import scala.compiletime.*
3+
4+
trait StringConverter[T]:
5+
def to(t: T): String
6+
7+
trait QueryParams
8+
trait QueryParamsConverter[T]:
9+
def to(t: T): QueryParams
10+
11+
object QueryParamsConverter {
12+
extension [T](t: T)
13+
def toQueryParams(using converter: QueryParamsConverter[T]): QueryParams = converter.to(t)
14+
15+
inline private def summonStringConverter[T]: StringConverter[T] = summonFrom {
16+
case converter: StringConverter[T] => converter
17+
case _ =>
18+
new StringConverter[T]: // warn
19+
override def to(t: T): String = t.toString
20+
}
21+
22+
inline def summonStringConverters[A <: Tuple]: List[StringConverter[?]] =
23+
inline erasedValue[A] match
24+
case _: EmptyTuple => Nil
25+
case _: (t *: ts) => summonStringConverter[t] :: summonStringConverters[ts]
26+
27+
inline def summonQueryParamsConverters[A <: Tuple]: List[QueryParamsConverter[?]] =
28+
inline erasedValue[A] match
29+
case _: EmptyTuple => Nil
30+
case _: (t *: ts) => summonInline[QueryParamsConverter[t]] :: summonQueryParamsConverters[ts]
31+
32+
inline given derived[T](using m: Mirror.Of[T]): QueryParamsConverter[T] = {
33+
val stringConverters = summonStringConverters[m.MirroredElemTypes]
34+
new QueryParamsConverter[T] { // warn
35+
override def to(t: T): QueryParams =
36+
inline m match
37+
case p: Mirror.ProductOf[T] => ???
38+
case s: Mirror.SumOf[T] =>
39+
val _ = summonQueryParamsConverters[m.MirroredElemTypes]
40+
???
41+
}
42+
}
43+
44+
}
45+
46+
object Test:
47+
sealed trait FutureOrderCreateParams
48+
object FutureOrderCreateParams:
49+
case class LIMIT(quantity: BigDecimal) extends FutureOrderCreateParams
50+
51+
case class FutureOrderCreateResponse(clientOrderId: String)
52+
53+
import QueryParamsConverter.*
54+
def createOrder(orderCreate: FutureOrderCreateParams) = orderCreate.toQueryParams

0 commit comments

Comments
 (0)