Incorrectly inferred: type mismatch: inferred type is MutableList<X> but ImmutableList<X> was expected
eggnstone opened this issue ยท 3 comments
error: type mismatch: inferred type is MutableList<X> but ImmutableList<X> was expected
parts = mutableListOf<X>()
interface X {}
//var parts: List<X> = listOf() // ok
var parts = listOf<X>() // error
parts = mutableListOf<X>()
Thanks for the report! This is expected, because in Dotlin we can guarantee that listOf
returns an ImmutableList
, not just a List
. So in your example, parts
would indeed have an inferred type of ImmutableList<X>
if the type is not specified explicitly.
Let me know what you think of this behavior!
Since you ask me what I think of it: I would expect working kotlin code to transpile without errors :)
Thanks for the input ๐ I didn't go that way because it would make interoperability with existing Dart code harder, and I think in the end it's nice to have interoperability with libraries made for the runtime they're supposed to run on, because with the other scenario you'd have Kotlin libraries being compiled for the Dart runtime, while they we're never made for that. Which brings other issues ๐
But I might, way down the line, add a "compat" mode where you could run existing Kotlin libraries. But that's a big maybe, since it's a huge amount of work ๐