From 3a1ed41436281ba0a8dd312794b4ca8989476a59 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Wed, 18 Jan 2017 21:16:49 +0300 Subject: [PATCH] Create deprecated MutableList.sort extensions to guide how to replace them. #KT-15790 Fixed --- .../testsWithJava8/targetedBuiltIns/blackListed.kt | 14 ++++++++++---- .../targetedBuiltIns/blackListed.txt | 1 + .../src/kotlin/collections/MutableCollections.kt | 10 ++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/compiler/testData/diagnostics/testsWithJava8/targetedBuiltIns/blackListed.kt b/compiler/testData/diagnostics/testsWithJava8/targetedBuiltIns/blackListed.kt index 89672092620..a280687db33 100644 --- a/compiler/testData/diagnostics/testsWithJava8/targetedBuiltIns/blackListed.kt +++ b/compiler/testData/diagnostics/testsWithJava8/targetedBuiltIns/blackListed.kt @@ -5,9 +5,15 @@ abstract class A : MutableList { } fun foo(x: MutableList, y: java.util.ArrayList, z: A, p: java.util.Comparator) { - // Resolved to extension with no parameters - x.sort(p) - y.sort(p) + x.sort(p) + y.sort(p) - z.sort(p) + z.sort(p) +} + +fun bar(x: MutableList, y: java.util.ArrayList, z: A) { + x.sort { a, b -> a.length - b.length } + y.sort { a, b -> a.length - b.length } + + z.sort { a, b -> a.length - b.length } } diff --git a/compiler/testData/diagnostics/testsWithJava8/targetedBuiltIns/blackListed.txt b/compiler/testData/diagnostics/testsWithJava8/targetedBuiltIns/blackListed.txt index bd546a2c88e..4ccb7b18290 100644 --- a/compiler/testData/diagnostics/testsWithJava8/targetedBuiltIns/blackListed.txt +++ b/compiler/testData/diagnostics/testsWithJava8/targetedBuiltIns/blackListed.txt @@ -1,5 +1,6 @@ package +public fun bar(/*0*/ x: kotlin.collections.MutableList, /*1*/ y: java.util.ArrayList, /*2*/ z: A): kotlin.Unit public fun foo(/*0*/ x: kotlin.collections.MutableList, /*1*/ y: java.util.ArrayList, /*2*/ z: A, /*3*/ p: java.util.Comparator): kotlin.Unit public abstract class A : kotlin.collections.MutableList { diff --git a/libraries/stdlib/src/kotlin/collections/MutableCollections.kt b/libraries/stdlib/src/kotlin/collections/MutableCollections.kt index 195dad391c9..5a1ae81c045 100644 --- a/libraries/stdlib/src/kotlin/collections/MutableCollections.kt +++ b/libraries/stdlib/src/kotlin/collections/MutableCollections.kt @@ -45,6 +45,16 @@ public inline fun <@kotlin.internal.OnlyInputTypes T> MutableCollection.r @kotlin.internal.InlineOnly public inline fun MutableList.remove(index: Int): T = removeAt(index) +@Deprecated("Use sortWith(comparator) instead.", ReplaceWith("this.sortWith(comparator)"), level = DeprecationLevel.ERROR) +@JvmVersion +@kotlin.internal.InlineOnly +public inline fun MutableList.sort(comparator: Comparator): Unit = throw NotImplementedError() + +@Deprecated("Use sortWith(Comparator(comparison)) instead.", ReplaceWith("this.sortWith(Comparator(comparison))"), level = DeprecationLevel.ERROR) +@JvmVersion +@kotlin.internal.InlineOnly +public inline fun MutableList.sort(comparison: (T, T) -> Int): Unit = throw NotImplementedError() + /** * Adds the specified [element] to this mutable collection. */