File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import java.math.{
2222 RoundingMode => JRM ,
2323}
2424import scala .collection .immutable .NumericRange
25+ import scala .runtime .ScalaRunTime .mapNull
2526
2627object BigDecimal {
2728 private final val maximumHashScale = 4934 // Quit maintaining hash identity with BigInt beyond this scale
@@ -304,8 +305,13 @@ object BigDecimal {
304305 /** Implicit conversion from `Double` to `BigDecimal`. */
305306 implicit def double2bigDecimal (d : Double ): BigDecimal = decimal(d)
306307
308+ // For the following function, both the parameter and the return type are non-nullable.
309+ // However, if a null reference is passed explicitly, this method will still return null.
310+ // We intentionally keep this signature to discourage passing nulls implicitly while
311+ // preserving the previous behavior for backward compatibility.
312+
307313 /** Implicit conversion from `java.math.BigDecimal` to `scala.BigDecimal`. */
308- implicit def javaBigDecimal2bigDecimal (x : BigDec | Null ): BigDecimal | Null = if (x == null ) null else apply(x)
314+ implicit def javaBigDecimal2bigDecimal (x : BigDec ): BigDecimal = mapNull(x, apply(x) )
309315}
310316
311317/**
Original file line number Diff line number Diff line change 1+ import java .math .{BigDecimal => JBigDecimal }
2+ import java .math .{BigInteger => JBigInteger }
3+
4+ opaque type CurrencyValue = BigDecimal
5+
6+ extension (value : CurrencyValue )
7+ def negate : CurrencyValue = value.bigDecimal.negate().nn
8+
9+ def testBigDecimalConversion (jbd : JBigDecimal ): BigDecimal = jbd
10+ def testBigIntConversion (jbi : JBigInteger ): BigInt = jbi
You can’t perform that action at this time.
0 commit comments