I have code like this. Task represent some set of operations and generic parameter represents return type of that operation.
``` fun perform<T>(task: Task<T>): T = when(task) { is Task.LoadPerson -> Person("john") } ```data class Person(val name: String)
sealed class Task<T> {
object LoadPerson: Task<Person>()
}Compiler marks type mismatch in perform function. Required: T found: Person. Maybe I'm just missing something but T cannot be anything else then Person. It works when I explicitly cast it to T.
Is it a limitation of Kotlin? Will it be possible in the future to write such code without typecast?