You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importscala.math.BigDecimalimportzio.*importzio.json.*importzio.prelude.{Equal, Validation}
importzio.schema.SchemaobjectPrice {
opaquetypePrice=BigDecimal// Factory method with Validation to ensure non-negative Pricedefmake(amount: BigDecimal):Validation[Chunk[String], Price] =Validation.fromPredicateWith(Chunk("Price must be non-negative"))(amount)(_ >=0)
// JSON codec for Price using zio-json, with conversions to handle java.math.BigDecimalgivenJsonCodec[Price] =JsonCodec.bigDecimal.transformOrFail(
amount => make(BigDecimal(amount)).toEither.left.map(_.mkString(", ")), // Handle Chunk errors
price => unwrap(price).bigDecimal // Converts scala.math.BigDecimal to java.math.BigDecimal
)
// Extension method to unwrap the Price back to BigDecimalextension (price: Price) {
defunwrap:BigDecimal= price
}
// Schema for Price using zio-schema, with validation to ensure non-negativegivenSchema[Price] =Schema[BigDecimal].transformOrFail(
amount => make(amount).toEither.left.map(_.mkString(", ")), // Handle Chunk errors
price =>Right(unwrap(price))
)
// Equality instance for Price using zio.preludegivenEqual[Price] =Equal.default
}
I receive the following compiler warning:
[warn] 40|Schema[BigDecimal].transformOrFail(
[warn] |^
[warn] |Result of implicit search for zio.schema.Schema[BigDecimal] will change.
[warn] |Current result given_Schema_Price will be no longer eligible
[warn] | because it is not defined before the search position.
[warn] |Resultwithnewrules: zio.schema.Schema.bigDecimal.
[warn] |To opt into the new rules, compile with`-source future` or use
[warn] |the `scala.language.future` language import.
[warn] |
[warn] |To fix the problem without the language import, you could try one of the following:
[warn] |- use a `given ... with` clause as the enclosing given,
[warn] |- rearrange definitions so that given_Schema_Price comes earlier,
[warn] |- use an explicit argument.
[warn] |This will be an error in Scala3.5 and later.
How do I future proof my code?
I tried to import zio.schema.Schema.bigDecimal but it does not get used.
I tried to replace the implicit definition as suggested in the warning message to:
[error] 40|givenSchema[Price] with {
[error] |^
[error] |Cannot extend sealedtraitSchema in a different source file
[error] |
[error] | longer explanation available when compiling with`-explain`
The text was updated successfully, but these errors were encountered:
Given the following opaque type:
I receive the following compiler warning:
How do I future proof my code?
I tried to
import zio.schema.Schema.bigDecimal
but it does not get used.I tried to replace the implicit definition as suggested in the warning message to:
but I get:
The text was updated successfully, but these errors were encountered: