workflow-kotlin
workflow-kotlin copied to clipboard
`BaseRenderContext.eventHandler(...)` has unsafe variance for `PropsT` and `OutputT`
trafficstars
When compiling against Kotlin 1.7.x, this code produces warnings:
public interface BaseRenderContext<out PropsT, StateT, in OutputT> {
// ...
public fun eventHandler(
name: () -> String = { "eventHandler" },
update: WorkflowAction<PropsT, StateT, OutputT>.Updater.() -> Unit
): () -> Unit {
return {
actionSink.send(action(name, update))
}
}
// ...
}
Type parameter PropsT is declared as 'out' but occurs in 'in' position in type WorkflowAction<PropsT, StateT, OutputT>.Updater.() -> Unit. This will become an error in Kotlin 1.9
All of the evenHandler() functions are the same.
Changing the variance in BaseRenderContext then requires changing it in RealRenderContext, but that's the only side effect within Workflow. That change does affect the public API, though.