title: Kotlin type mismatch compile error: Require Success<T>, Found MyError
body: <p>I am encountering an issue that the following code can't be compiled in kotlin.</p>
  
  <pre><code>// StateModel.kt
  sealed class StateModel
  class Loading : StateModel()
  data class Success&lt;T: Any&gt;(val data: T) : StateModel()
  data class MyError(val message: String) : StateModel()
  
  // StateModelTransformer.kt
  class StateModelTransformer&lt;T: Any&gt; : FlowableTransformer&lt;T, StateModel&gt; {
  
    override fun apply(upstream: Flowable&lt;T&gt;): Publisher&lt;StateModel&gt; {
      return upstream
        .map { data -&gt; Success(data) }
        .onErrorReturn { error -&gt;
          MyError(error.message)  // compile error, Type mismatch, Require Success&lt;T&gt;, Found MyError
        }
        .startWith(Loading()) // compile error, none of the following function can be called with the arguments supplied
    }
  
  }
  </code></pre>
  
  <p>I have no idea why the <code>onErrorReturn</code> says requiring a <code>Success&lt;T&gt;</code> type but a <code>StateModel</code> type.</p>
  
  <p>Thanks</p>