zio / zio-json

Fast, secure JSON library with tight ZIO integration.
https://zio.dev/zio-json
Apache License 2.0
410 stars 147 forks source link

Discriminating case classes causes compiler error in Scala 3.1.3 with Tapirs Zio JSON support (Tapir version 1.0.5) #713

Closed longliveenduro closed 2 years ago

longliveenduro commented 2 years ago

I use the following code

sealed trait PositionHint

case class CellPositionHint(
    cellType: CellType,
    mnc: String,
    mcc: String,
    cid: Int,
    lac: Option[Int],
    signalStrength: Option[Int],
    sinr: Option[Int]
) extends PositionHint

object CellPositionHint:
  enum CellType:
    case LTE, GSM, WCDMA, NBIOT, LTEM

case class WlanPositionHint(mac: String) extends PositionHint

case class DeviceLocation(hints: Seq[PositionHint])

and the following Tapir endpoint definition:

val positionInfoEndpoint: PublicEndpoint[DeviceLocation, Unit, GeolocationServiceResult, Any] =
    endpoint.post
      .in("position-info")
      .in(jsonBody[DeviceLocation])
      .out(jsonBody[GeolocationServiceResult])

I get the following compiler error

error] -- Error: /home/chris/prj/toil/zio-geolocation/modules/core/src/main/scala/com/tsystems/toil/geolocation/rest/Endpoints.scala:21:34 
[error]  21 |      .in(jsonBody[DeviceLocation])
[error]     |                                  ^
[error]     |     method deriveSubtype is declared as `inline`, but was not inlined
[error]     |
[error]     |     Try increasing `-Xmax-inlines` above 32
[error]     |---------------------------------------------------------------------------
[error]     |Inline stack trace
[error]     |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[error]     |This location contains code that was inlined from impl.scala:136
....
longliveenduro commented 2 years ago

Sorry, not a ZIO-JSON bug, but a Tapir bug, see https://github.com/softwaremill/tapir/issues/2383