Macro arguments are type-checked against the parameter types of the macro prior to instantiating the macro.
macro stringify<T>(_: T) -> (T, String)
But what about scenario where I might want to construct type based on the input provided, i.e. building a type from json string:
macro jsonObj<T>(_: String) -> T
let obj = #jsonObj("""
{
"one": 1,
"two": 2
}
""")
Or registering routes in a server framework:
app.get("hello/:name") { req in
// req could be inferred from the provided string as
// SomeGenericStruct<(name: String)>
let name = req.parameters.name
return "Hello, \(name)!"
}
Although, such scenario can degrade compile-time performance by having to expand the macro for type inference, but having this as an option would be really beneficial.