# Type projection: inherently broken?

**URL:** <https://discuss.kotlinlang.org/t/type-projection-inherently-broken/1380>\
**Category:** Support\
**Created:** [December 26, 2015, 7:41pm UTC](https://discuss.kotlinlang.org/t/type-projection-inherently-broken/1380 "2015-12-26T19:41:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jdoe](https://avatars.discourse-cdn.com/v4/letter/j/eb8c5e/32.png) [@jdoe](https://discuss.kotlinlang.org/u/jdoe)\
**Post date:** [December 26, 2015, 7:41pm UTC](https://discuss.kotlinlang.org/t/type-projection-inherently-broken/1380/1 "2015-12-26T19:41:13Z")

</div>

Here’s an excerpt from the reference:

```
fun copy(from: Array<out Any>, to: Array<Any>) {
 // ...
}

```

_What has happened here is called type projection: we said that from is not simply an array, but a restricted (projected) one: we can only call those methods that return the type parameter T, in this case it means that we can only call get()._

But if I slightly modify the example:

```
fun copy(from: MutableList<out Any>, to: MutableList<Any>) {
    // ...
}

```

then I’m able to execute both these statements in its body:

```
to.addAll(from) // ok
from.addAll(to) // SHOULD BE PROHIBITED!

```

Why Kotlin allowed me to do this?  
Now some “funny” things become possible:

```
val from: ArrayList<String> = arrayListOf("a", "b", "c")
val to: ArrayList<Any> = arrayListOf(1, 2, 3)
copy(from, to)
println(from) // [a, b, c, 1, 2, 3] <--- only strings are supposed to be here!

```

---

<div class="post-metadata">

**Author:** ![ilya.gorbunov](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/ilya.gorbunov/32/1645_2.png) [@ilya.gorbunov](https://discuss.kotlinlang.org/u/ilya.gorbunov)\
**Post date:** [December 28, 2015, 4:20pm UTC](https://discuss.kotlinlang.org/t/type-projection-inherently-broken/1380/2 "2015-12-28T16:20:20Z")

</div>

Hi, we’re aware of this problem with type projections and have already fixed it in master (1.0.0-beta-5160).  
Thanks for drawing our attention.
