cornerman / sloth

Type safe RPC in scala
MIT License
95 stars 11 forks source link

Client wire fails due to failed implicit search (Scala 3) #213

Closed ioleo closed 1 year ago

ioleo commented 1 year ago
import chameleon.ext.zioJson.given
import sloth.*
import zio.*

// ...
trait NewsRpc {
  def listPaged(limit: Int, offset: Int): Task[NewsListResponse]
}
// ...
val client = Client[String, Task](transport)
client.wire[NewsRpc] 

/* 
[error]    |No given instance of type chameleon.Serializer[((page : Int), (limit : Int)), String] was found for parameter serializer of method execute in class ClientImpl.
[error]    |I found:
[error]    |
[error]    |       33|chameleon.ext.zioJson.zioJsonToString[((page : Int), (limit : Int))](
[error]    |       33|  zio.json.JsonCodec.tuple2[(page : Int), (limit : Int)](
[error]    |       33|    zio.json.JsonEncoder.fromCodec[(page : Int)](
[error]    |          /* missing */summon[zio.json.JsonCodec[(page : Int)]]),
[error]    |      ???, ???, ???)
[error]    |    )
[error]    |
[error]    |But no implicit values were found that match type zio.json.JsonCodec[(page : Int)].
*/

Yet in the same file:

// commeting out the failing part
// client.wire[NewsRpc] 
// all of following compile
  summon[JsonCodec[Int]]
  summon[JsonCodec[(Int, Int)]]
  summon[chameleon.Serializer[Int, String]]
  summon[chameleon.Serializer[(Int, Int), String]]

So basically, the compiler tells me it can't find an implicit, which I can summon manually in the same scope. I'm out of ideas, perhaps this is somehow related to macro implementation? Just a wild guess.

cornerman commented 1 year ago

Thank you for opening this issue. This looks very similar to this one here: #203

ioleo commented 1 year ago

Minimal reproduction, although in Scastie it fails with another error (because it uses cross CrossVersion.for3Use2_13 unfortunately), but you can copy/paste into your module for testing. https://scastie.scala-lang.org/mnEh4DvmSdmK9Cq0eb9kdw

cornerman commented 1 year ago

Thank you! I will need to check more in detail. But it looks to me like this line is somehow wrong: https://github.com/cornerman/sloth/blob/master/sloth/src/main/scala-3/internal/Macros.scala#L174

It seems to take the argument names and types in the tuple type: ((page : Int), (limit : Int))

ioleo commented 1 year ago

Added minimal repro to my fork https://github.com/ioleo/sloth (try sbt examples/compile)

I made the examples project depend on sloth, so you can immidietly test changes. I'll try to resolve this myself, but I'm totally new to Scala 3 macros so not much hope here :)

cornerman commented 1 year ago

Fix is released in version 0.7.1.

I have added a test-case accordingly. Still, please let me know, if the issue persists for you.