amnaredo / test

0 stars 0 forks source link

Failing to find usable reader implicit forsimple case class #123

Open amnaredo opened 3 years ago

amnaredo commented 3 years ago

I seem to be running into issues using upickle 0.2.8 with Scala.js when reading a simple case class. Here is a distilled version of code that consistently yields a failed compileation:

package example
import org.scalajs.dom
import scalajs.js._
import scalajs.js.annotation.JSExport                                                                                                                                      
import scala.concurrent.{Future, Promise}
import scala.util.{Try, Success, Failure}
import scalatags.JsDom.all._
import upickle._
import rx._
import rx.ops._
import dom.html

case class Foo(x:String)

object ClientApi extends Api {
  import scalajs.concurrent.JSExecutionContext.Implicits.runNow
  import dom.ext.Ajax

  def foo(): Future[Foo] = {
    Ajax.get(
        url = "/foo"
    ).map(r => read[Foo](r.responseText))
  }
}

When I compile this, I get the following exception:

[error] /home/jmatlik/tmp/scalajs/workbench-exampl-app/example/js/src/main/scala/example/ScalaJSExample.scala:23: type mismatch;
[error]  found   : scala.scalajs.js.Array[String]
[error]  required: scala.Array[String]
[error]     ).map(r => read[Foo](r.responseText))
[error]                         ^
[error] one error found

I am using 2.11.2 <= scala <= 2.11.6 and "com.lihaoyi" %%% "upickle" % "0.2.8", "com.lihaoyi" %%% "scalatags" % "0.4.5", "org.scala-js" %%% "scalajs-dom" % "0.8.0", "com.lihaoyi" %%% "scalarx" % "0.2.8"

Thanks, James

ID: 83 Original Author: matlik

amnaredo commented 3 years ago

I believe this is due to conflicting wildcard imports. Is there a reason you're importing scalajs.js._? Please verify that read really points to uPickle.

Original Author: tindzk

amnaredo commented 3 years ago

Yes, you are spot on. I suspected implicit import collisions were causing other issues in my code, but not in this code, as it works with other standard types. Much thanks!

Original Author: matlik