I'm struggling to get information of type in Scala3 macro implementation. I'll explain problem through code.
Here is application logic:
object BlockServiceImpl extends BlockService:
def authenticateUser0() = new ServiceCall[AuthUser,AuthUserResponse]:
def invoke(request: AuthUser): Future[AuthUserResponse] =
println("BlockServiceImpl authenticateUser0 called")
Future.successful(AuthUserResponse("test"))
Now, for the logic I want to make endpoints with help of macro.
defineRoute("POST","/v1/block",BlockServiceImpl.authenticateUser0)
This is inline method:
inline def defineRoute[Q: RootJsonFormat ,R: RootJsonFormat](method: String, uri: String,inline call: () => ServiceCall[Q,R]): AkkaHttpCall = ${ methodImpl[Q,R]('uri, 'call)}
And this is implementation of macro:
def methodImpl[Q: Type,R: Type](uri: Expr[String],expr: Expr[Function0[ServiceCall[Q,R]]])(using ctx: Quotes): Expr[AkkaHttpCall] = ...
How can I get information that Q
is AuthUser
type during macro expansion in a compile time?
Q: Type, R: Type
you have no bounds on yourmethodImpl
, can you bind them accordingly? (I'm not super familiar with the new macros, but how can you enforce a certain type if the type has no bounds?) – GrammarQ <: AuthUser : Type
. – Edwardedwardian