Giter VIP home page Giter VIP logo

Comments (4)

jhegedus42 avatar jhegedus42 commented on August 20, 2024

this even simpler code has similar issues :


      trait MyApi {
        def foo[T:MyReader](t:T):String
      }

      // server-side implementation, and router
      object MyApiImpl extends MyApi {
        override def foo[T:MyReader](t: T): String = ???
      }

      trait MyReader[T] {}

      implicit val mr: MyReader[String] = ???
      implicit val mwsw: MyWriter[String] = ???

      trait MyWriter[T] {}

      // we serialize into String
      trait MyServer extends autowire.Server[String, MyReader, MyWriter] {
        def write[Result: MyWriter](r: Result): String = ???

        def read[Result: MyReader](p: String): Result = ???

      }

  object MyServerObj extends MyServer{

    val routes: PartialFunction[Core.Request[String], Future[String]] = MyServerObj.route[MyApi](MyApiImpl)
  }

gives :

Error:(43, 97) could not find implicit value for evidence parameter of type autowire.TypeParameterTest.MyReader[autowire.TypeParameterTest.MyReader[T]]
    val routes: PartialFunction[Core.Request[String], Future[String]] = MyServerObj.route[MyApi](MyApiImpl)
Error:(43, 97) not enough arguments for method read: (implicit evidence$4: autowire.TypeParameterTest.MyReader[autowire.TypeParameterTest.MyReader[T]])autowire.TypeParameterTest.MyReader[T].
Unspecified value parameter evidence$4.
    val routes: PartialFunction[Core.Request[String], Future[String]] = MyServerObj.route[MyApi](MyApiImpl)
Error:(43, 97) could not find implicit value for evidence parameter of type autowire.TypeParameterTest.MyReader[T]
    val routes: PartialFunction[Core.Request[String], Future[String]] = MyServerObj.route[MyApi](MyApiImpl)
Error:(43, 97) not enough arguments for method read: (implicit evidence$4: autowire.TypeParameterTest.MyReader[T])T.
Unspecified value parameter evidence$4.
    val routes: PartialFunction[Core.Request[String], Future[String]] = MyServerObj.route[MyApi](MyApiImpl)
Error:(43, 97) could not find implicit value for evidence parameter of type autowire.TypeParameterTest.MyReader[(T, autowire.TypeParameterTest.MyReader[T])]
    val routes: PartialFunction[Core.Request[String], Future[String]] = MyServerObj.route[MyApi](MyApiImpl)
Error:(43, 97) not enough arguments for method foo: (implicit evidence$2: autowire.TypeParameterTest.MyReader[(T, autowire.TypeParameterTest.MyReader[T])])String.
Unspecified value parameter evidence$2.
    val routes: PartialFunction[Core.Request[String], Future[String]] = MyServerObj.route[MyApi](MyApiImpl)

the macro here expands into :

Warning:scala: (RES,(<empty> match {
  case autowire.Core.Request(Seq("autowire", "TypeParameterTest", "MyApi", "foo"), (args$macro$1 @ _)) => autowire.Internal.doValidate({
    <synthetic> <artifact> val x$4 = autowire.Internal.read[String, autowire.TypeParameterTest.MyReader[T]](args$macro$1, scala.util.Left(autowire.Error.Param.Missing("evidence$1")), "evidence$1", ((x$2) => TypeParameterTest.this.MyServerObj.read[autowire.TypeParameterTest.MyReader[T]](x$2)));
    {
  <synthetic> <artifact> val x$3 = autowire.Internal.read[String, T](args$macro$1, scala.util.Left(autowire.Error.Param.Missing("t")), "t", ((x$1) => TypeParameterTest.this.MyServerObj.read[T](x$1)));
  Nil.$colon$colon(x$3)
}.$colon$colon(x$4)
  }) match {
    case scala.$colon$colon((evidence$1 @ (_: autowire.TypeParameterTest.MyReader[T] @unchecked)), scala.$colon$colon((t @ (_: T @unchecked)), Nil)) => scala.concurrent.Future(TypeParameterTest.this.MyApiImpl.foo(t, evidence$1)).map(((x$5) => TypeParameterTest.this.MyServerObj.write(x$5)))
    case _ => $qmark$qmark$qmark
  }
  case autowire.Core.Request(Seq("autowire", "TypeParameterTest", "MyApi", "foo"), (args$macro$2 @ _)) => autowire.Internal.doValidate({
    <synthetic> <artifact> val x$9 = autowire.Internal.read[String, autowire.TypeParameterTest.MyReader[T]](args$macro$2, scala.util.Left(autowire.Error.Param.Missing("evidence$1")), "evidence$1", ((x$7) => TypeParameterTest.this.MyServerObj.read[autowire.TypeParameterTest.MyReader[T]](x$7)));
    {
  <synthetic> <artifact> val x$8 = autowire.Internal.read[String, T](args$macro$2, scala.util.Left(autowire.Error.Param.Missing("t")), "t", ((x$6) => TypeParameterTest.this.MyServerObj.read[T](x$6)));
  Nil.$colon$colon(x$8)
}.$colon$colon(x$9)
  }) match {
    case scala.$colon$colon((evidence$1 @ (_: autowire.TypeParameterTest.MyReader[T] @unchecked)), scala.$colon$colon((t @ (_: T @unchecked)), Nil)) => scala.concurrent.Future(TypeParameterTest.this.MyApiImpl.foo(t, evidence$1)).map(((x$10) => TypeParameterTest.this.MyServerObj.write(x$10)))
    case _ => $qmark$qmark$qmark
  }
}: autowire.Core.Router[String]))

from autowire.

jhegedus42 avatar jhegedus42 commented on August 20, 2024

think the problem might be that implicit parameters are not supported by autowire at all : https://gitter.im/scala-js/scala-js?at=58ff1dbc08c00c092ab30da7

and this type class constraint here is implemented by implicit arguments : override def foo[T:MyReader](t: T): String = ???

from autowire.

bbarker avatar bbarker commented on August 20, 2024

@jhegedus42 I think I may have hit this problem as well; hope to look into it more later today. Did you ever find a workaround?

from autowire.

jhegedus42 avatar jhegedus42 commented on August 20, 2024

Sorry for late answer :)

this is an inherent limitation in Autowire ... if you think about it a bit deeper then it is kinda understandable ... it would be pretty difficult to do this ... with macros, or otherwise... sure it is doable ... in principle ... but then the macros would need to look explicitly into the type parameters at compile time ... which they are not doing right now... and probably never will... kinda deal breaker... IMHO ...

so i have a workaround, but it wont help you much, yet : i wrote my own autowire :) sort of... no macros ... no nothing... just type classes and lot of type hackery ... and it is simple REST ... no magic ... i am not sure it was worth it ... but it seems to be working so far... i plan to put it to github once it is in some publishable form... the way i see it that will be 1 year from now :( ... got a bit busy with work ...

from autowire.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.