From 2520f11bdc5bf2187c55721c3038df6eb75e16df Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Tue, 30 Jul 2013 01:18:05 +0400 Subject: [PATCH] KT-3823 Standard sort function requires MutableIterable by no reason #KT-3823 Fixed --- libraries/stdlib/src/kotlin/IterablesSpecial.kt | 2 +- libraries/stdlib/test/CollectionTest.kt | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/libraries/stdlib/src/kotlin/IterablesSpecial.kt b/libraries/stdlib/src/kotlin/IterablesSpecial.kt index 62aff9516be..17004f9ee68 100644 --- a/libraries/stdlib/src/kotlin/IterablesSpecial.kt +++ b/libraries/stdlib/src/kotlin/IterablesSpecial.kt @@ -64,7 +64,7 @@ public fun Iterable.containsItem(item : T) : Boolean { } -public inline fun > MutableIterable.sort() : List { +public inline fun > Iterable.sort() : List { val list = toCollection(ArrayList()) java.util.Collections.sort(list) return list diff --git a/libraries/stdlib/test/CollectionTest.kt b/libraries/stdlib/test/CollectionTest.kt index 89bb02a1e15..f20eeb16393 100644 --- a/libraries/stdlib/test/CollectionTest.kt +++ b/libraries/stdlib/test/CollectionTest.kt @@ -402,6 +402,18 @@ class CollectionTest { // assertFalse(IterableWrapper(linkedList()).contains(15)) } + test fun sortForMutableIterable() { + val list : MutableIterable = arrayList(2, 3, 1) + expect(arrayList(1, 2, 3)) { list.sort() } + expect(arrayList(2, 3, 1)) { list } + } + + test fun sortForIterable() { + val list : Iterable = listOf(2, 3, 1) + expect(arrayList(1, 2, 3)) { list.sort() } + expect(arrayList(2, 3, 1)) { list } + } + class IterableWrapper(collection : Iterable) : Iterable { private val collection = collection