Comments (4)
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.
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.
@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.
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)
- Pickle type for traits in method arguments HOT 1
- Custom header HOT 1
- cross-publish for 2.13.0-M1 HOT 5
- Can't Use API Factory Functions for Namespacing Purposes HOT 3
- Strange exception "autowire.Error$InvalidInput" with no message
- How to support server-side injection of data into API calls? HOT 4
- Possible issue using ClassTag in autowire calls HOT 1
- Support for implicit parameters in method?
- Can not assign server.route to a val and use that
- scala.MatchError of class autowire.Core$Request HOT 1
- Cannot find proxy for ...
- Parameterize effect type HOT 1
- Compilation fails in Scala 2.12.8 if one or more parameters have default values defined in the API trait HOT 3
- Need a license for this project HOT 2
- Allow customization of the API endpoint
- Autowire in AWS Lambda Java runtime HOT 1
- Autowire maintenance HOT 11
- Scala 3 support HOT 6
- assignments
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from autowire.