softwaremill / sttp

The Scala HTTP client you always wanted!
https://sttp.softwaremill.com
Apache License 2.0
1.44k stars 301 forks source link

Update to zio 2.1.x for sttp 3.9.x #2243

Open dlagnohed opened 1 month ago

dlagnohed commented 1 month ago

In order to run sttp with the latest zio version, a new release is necessary. This issue affects the sttp3-branch branch.

adamw commented 1 month ago

Can you create a PR against the sttp3 branch?

dlagnohed commented 1 month ago

I'm not sure if there's another way to do this besides commenting in the issue description.

adamw commented 1 month ago

I meant a PR such as: https://github.com/softwaremill/sttp/pull/2244 Let's see if the tests pass

adamw commented 1 month ago

Unfortunately after update the Scala 3 version starts failing with:

[error] -- [E172] Type Error: /home/runner/work/sttp/sttp/effects/zio/src/main/scalajvm/sttp/client3/httpclient/zio/HttpClientZioBackend.scala:162:5 
[error] 162 |    )
[error]     |     ^
[error]     |could not find implicit value for izumi.reflect.Tag[sttp.client3.SttpBackend[zio.Task, sttp.capabilities.zio².ZioStreams &
[error]     |  sttp.capabilities.WebSockets]]. Did you forget to put on a Tag, TagK or TagKK context bound on one of the parameters in sttp.client3.SttpBackend[zio.Task, sttp.capabilities.zio².ZioStreams &
[error]     |  sttp.capabilities.WebSockets]? e.g. def x[T: Tag, F[_]: TagK] = ....
[error]     |I found:
[error]     |
[error]     |    zio.Tag.materialize[
[error]     |      
[error]     |        sttp.client3.SttpBackend[zio.Task, sttp.capabilities.zio².ZioStreams &
[error]     |          sttp.capabilities.WebSockets]
[error]     |      
[error]     |    ]
[error]     |
[error]     |But method materialize in trait TagVersionSpecific does not match type zio.Tag[
[error]     |  sttp.client3.SttpBackend[zio.Task, sttp.capabilities.zio².ZioStreams &
[error]     |    sttp.capabilities.WebSockets]
[error]     |]
[error]     |
[error]     |where:    zio  is a package
[error]     |          zio² is a package in package sttp.capabilities
[error]     |.

After providing the tag explicitly in HttpClientZioBackend:162:

ZLayer.scoped.apply(
      (for {
        backend <- HttpClientZioBackend(
          options,
          customizeRequest,
          customEncodingHandler
        )
      } yield backend).tap(client => ZIO.addFinalizer(client.close().ignore))
    )(zio.Tag.materialize[SttpBackend[Task, ZioStreams with WebSockets]])

I get:

[error] 162 |    )(zio.Tag.materialize[SttpBackend[Task, ZioStreams with WebSockets]])
[error]     |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]     |You must not use an intersection type, yet have provided sttp.capabilities.zio.ZioStreams & sttp.capabilities.WebSockets

However this doesn't offer any solutions to the problem, just that the intersection type might be the cause for the original compiler failure.

Something must have changed between ZIO 2.0 and 2.1, but I think somebody with deeper ZIO knowledge would have to help with this one.