Verify inline functions with reified and crossinline params
kristiyanP opened this issue · comments
Kristiyan Petrov commented
Is it possible to verify a function like this?
inline fun <reified T> Socket.emitTyped(event: String,
objectToEmit: Any?,
crossinline success: (response: T) -> Unit,
crossinline error: (reason: String) -> Unit)
Oleksiy Pylypenko commented
@kristiyanP, unfortunately, it is not possible as no method with bytecode is produced. I heard this question already few times. It would require a totally different approach to solve. For example writing an annotation processor. I am thinking about it, as this can probably make it possible to run on Android devices.
Sri Harsha Chilakapati commented
Why not wrap it in a regular function and test that instead? Wouldn't that work?
inline fun <reified T> Socket.emitTyped(event: String,
objectToEmit: Any?,
crossinline success: (response: T) -> Unit,
crossinline error: (reason: String) -> Unit) {
// Some code which gets inlined
}
fun <T> emitTypedWrapper(event: String,
objectToEmit: Any?,
success: (response: T) -> Unit,
error: (reason: String) -> Unit) {
// This will be replaced with code inside the inline function by compiler
Socket.emitTyped(event, objectToEmit, success, error)
}
Now write your tests with the wrapper function.