# A confusing compiler error for immutable List

**URL:** <https://discuss.kotlinlang.org/t/a-confusing-compiler-error-for-immutable-list/1012>\
**Category:** Uncategorized\
**Created:** [November 18, 2012, 8:14pm UTC](https://discuss.kotlinlang.org/t/a-confusing-compiler-error-for-immutable-list/1012 "2012-11-18T20:14:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![saltnlight5](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/saltnlight5/32/1525_2.png) [@saltnlight5](https://discuss.kotlinlang.org/u/saltnlight5)\
**Post date:** [November 18, 2012, 8:14pm UTC](https://discuss.kotlinlang.org/t/a-confusing-compiler-error-for-immutable-list/1012/1 "2012-11-18T20:14:01Z")

</div>

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.

``

```kotlin
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?

Zemian

---

<div class="post-metadata">

**Author:** ![abreslav](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/abreslav/32/8279_2.png) [@abreslav](https://discuss.kotlinlang.org/u/abreslav)\
**Post date:** [November 19, 2012, 9:48am UTC](https://discuss.kotlinlang.org/t/a-confusing-compiler-error-for-immutable-list/1012/2 "2012-11-19T09:48:36Z")

</div>

This looks very much like an issue report. Please use the [bug tracker](http://youtrack.jetbrains.net/issues/KT) for this kind of things.

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

---

<div class="post-metadata">

**Author:** ![saltnlight5](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/saltnlight5/32/1525_2.png) [@saltnlight5](https://discuss.kotlinlang.org/u/saltnlight5)\
**Post date:** [November 21, 2012, 4:42am UTC](https://discuss.kotlinlang.org/t/a-confusing-compiler-error-for-immutable-list/1012/3 "2012-11-21T04:42:19Z")

</div>

[http://youtrack.jetbrains.com/issue/KT-3058](http://youtrack.jetbrains.com/issue/KT-3058)
