A confusing compiler error for immutable List

When I run the following, I would expect the compiler to give me a nice error that says "ERROR: You may not change an immutable List<Int> variable 'ls4'.", but I get an suprising and confusing msg instead.


val ls3 : MutableList<Int> = arrayList(1,2,3)
ls3[0] = 93 // This should be ok
val ls4 : List<Int> = arrayList(1,2,3)
ls4[0] = 94 // We should get compiler error here.

> output
ERROR: /Users/zemian/apps/kotlinc-0.4.177/Test.kt: (5, 2) Type inference failed: fun <K, V> jet.MutableMap<K, V>.set(key : K, value : V) : V?
cannot be applied to
receiver: jet.List<jet.Int>  arguments: (jet.Int,jet.Int)
ERROR: /Users/zemian/apps/kotlinc-0.4.177/Test.kt: (5, 5) No set method providing array access

Should/can Kotlin improve on this?


1 Like

This looks very much like an issue report. Please use the bug tracker for this kind of things.

P.S. Yes, the diagnostics should be improved.