workflow-kotlin icon indicating copy to clipboard operation
workflow-kotlin copied to clipboard

`BaseRenderContext.eventHandler(...)` has unsafe variance for `PropsT` and `OutputT`

Open RBusarow opened this issue 3 years ago • 0 comments
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.

RBusarow avatar Oct 27 '22 21:10 RBusarow