raulraja
08/01/2017, 6:56 PM@implicit fun provideIntList(): List<Int> = listOf(1,2,3)
inline fun <reified A> la(@implicit l: List<A>): List<A> = l
val lint: List<Int> = <http://target.la|target.la><Int>()
My understanding is that the annotation processor has no visibility as to where lint
is. You mentioned that:
...what you would want is to generate one function for every generic provider, and then change the bytecode (at call site) to swap every generic invocation with the actual specific function
the annotation processor can do all the analysis and code generation, but there has to be another step to swap those invocations in the bytecode.
In that case even if we were able to replace the invocations in the bytecode some of those invocations are actually of this form:
inline fun <reified A> addToList(a: A, @implicit l: List<A>): List<A> = l + a
And those methods need to work for any A
provided there is a List<A>
implicit provided, in this case provideIntList()
whenever A
is Int
.
Meaning the compiler should bail when addToList<String>("a")
is declared but compile when addToList<Int>(1)
is declared because provideIntList()
is available implicitly.
Scala uses the typechecking phase to do implicit resolution AFAIK so even with bytecode injection we would not be able to support this at compile time?
If that is the case only runtime lookups are the option to support generic args which are most of the cases in Kategory. Thoughts?