autowire icon indicating copy to clipboard operation
autowire copied to clipboard

Possible issue using ClassTag in autowire calls

Open bbarker opened this issue 8 years ago • 1 comments
trafficstars

I had a working API that looked like

final case class OneShot(id: CommandId, body: String, meta: SysCmdMetaData)
extends Command[SysCmdMetaData]

def exec(data: List[OneShot]): Future[List[RunResult]]

with the js implementation of exec being:

  def exec(cmds: List[OneShot]): Rx[List[RunResult]] = {
    println("Verifying outer exec is called")
    AutowireClient[Api].exec(cmds).call().toRx.map {
      case Some(attempt) => attempt match {
        case Success(output) => output
        case Failure(err) =>
          List(RunResult.fakeResult(s"Error: ${err.getCause}!", NONFATAL_APP_ERR))
      }
      case None => List(RunResult.fakeResult(""))
    }
  }

In an attempt to generify things a bit, I changed the API's exec signature to:

  def exec[M <: CommandMetaData : ClassTag, C <: Command[M] : ClassTag]
  (data: List[C]): Future[List[RunResult]]

and the implementation to:

  def exec[M <: CommandMetaData : ClassTag, C <: Command[M] : ClassTag]
  (cmds: List[C]): Rx[List[RunResult]] = {
    println("Verifying outer exec is called")
    AutowireClient[Api].exec[M, C](cmds).call().toRx.map {
      case Some(attempt) => attempt match {
        case Success(output) => output
        case Failure(err) =>
          List(RunResult.fakeResult(s"Error: ${err.getCause}!", NONFATAL_APP_ERR))
      }
      case None => List(RunResult.fakeResult(""))
    }
  }

This results in the compile error:

You can't call the .call() method on autowire.`package`.unwrapClientProxy[model.Api, java.nio.ByteBuffer, boopickle.Default.Pickler, boopickle.Default.Pickler](client.AutowireClient.apply[model.Api]).exec[M, C](cmds)(evidence$1, evidence$2), only on autowired function calls.
[error]     AutowireClient[Api].exec[M, C](cmds).call().toRx.map {```

bbarker avatar Sep 23 '17 19:09 bbarker

Here's a workaround I ended up using. I got rid of all the type parameters, and just used type members instead, passing in subclasses that have the requisite type members as necessary to help with type inference.

bbarker avatar Apr 17 '18 21:04 bbarker