From 54b415593a95e2e231918cd4c09632399b8aad38 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Thu, 26 Nov 2015 06:14:25 +0300 Subject: [PATCH] Replacement upcasts parameter to the most specific supertype in case of contains, indexOf, lastIndexOf, remove, get, containsKey, containsValue. --- libraries/stdlib/src/generated/_Arrays.kt | 12 +++++------ .../stdlib/src/generated/_Collections.kt | 20 +++++++++---------- libraries/stdlib/src/generated/_Sequences.kt | 12 +++++------ .../kotlin/collections/MutableCollections.kt | 16 +++++++-------- .../src/templates/Elements.kt | 6 +++--- 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/libraries/stdlib/src/generated/_Arrays.kt b/libraries/stdlib/src/generated/_Arrays.kt index f2e94aae0b1..76363a716c6 100644 --- a/libraries/stdlib/src/generated/_Arrays.kt +++ b/libraries/stdlib/src/generated/_Arrays.kt @@ -438,11 +438,11 @@ public operator fun ShortArray.contains(element: Short): Boolean { /** * Returns `true` if [element] is found in the collection. */ -@Deprecated("Array and element have incompatible types. Upcast element to Any? if you're sure.", ReplaceWith("contains(element as Any?)")) +@Deprecated("Array and element have incompatible types. Upcast element to Any? if you're sure.", ReplaceWith("contains(element as T)")) @kotlin.jvm.JvmName("containsAny") @kotlin.internal.LowPriorityInOverloadResolution public operator fun Array.contains(element: T): Boolean { - return contains(element as Any?) + return contains(element as T) } /** @@ -1321,12 +1321,12 @@ public fun ShortArray.indexOf(element: Short): Int { /** * Returns first index of [element], or -1 if the collection does not contain element. */ -@Deprecated("Array and element have incompatible types. Upcast element to Any? if you're sure.", ReplaceWith("indexOf(element as Any?)")) +@Deprecated("Array and element have incompatible types. Upcast element to Any? if you're sure.", ReplaceWith("indexOf(element as T)")) @kotlin.jvm.JvmName("indexOfAny") @kotlin.internal.LowPriorityInOverloadResolution @Suppress("NOTHING_TO_INLINE") public fun Array.indexOf(element: T): Int { - return indexOf(element as Any?) + return indexOf(element as T) } /** @@ -1872,12 +1872,12 @@ public fun ShortArray.lastIndexOf(element: Short): Int { /** * Returns last index of [element], or -1 if the collection does not contain element. */ -@Deprecated("Array and element have incompatible types. Upcast element to Any? if you're sure.", ReplaceWith("lastIndexOf(element as Any?)")) +@Deprecated("Array and element have incompatible types. Upcast element to Any? if you're sure.", ReplaceWith("lastIndexOf(element as T)")) @kotlin.jvm.JvmName("lastIndexOfAny") @kotlin.internal.LowPriorityInOverloadResolution @Suppress("NOTHING_TO_INLINE") public fun Array.lastIndexOf(element: T): Int { - return lastIndexOf(element as Any?) + return lastIndexOf(element as T) } /** diff --git a/libraries/stdlib/src/generated/_Collections.kt b/libraries/stdlib/src/generated/_Collections.kt index 33905f1991c..4b84788adae 100644 --- a/libraries/stdlib/src/generated/_Collections.kt +++ b/libraries/stdlib/src/generated/_Collections.kt @@ -64,11 +64,11 @@ public operator fun <@kotlin.internal.OnlyInputTypes T> Iterable.contains(ele /** * Returns `true` if [element] is found in the collection. */ -@Deprecated("Collection and element have incompatible types. Upcast element to Any? if you're sure.", ReplaceWith("contains(element as Any?)")) +@Deprecated("Collection and element have incompatible types. Upcast element to Any? if you're sure.", ReplaceWith("contains(element as T)")) @kotlin.jvm.JvmName("containsAny") @kotlin.internal.LowPriorityInOverloadResolution public operator fun Iterable.contains(element: T): Boolean { - return contains(element as Any?) + return contains(element as T) } /** @@ -281,23 +281,23 @@ public fun <@kotlin.internal.OnlyInputTypes T> List.indexOf(element: T): Int /** * Returns first index of [element], or -1 if the collection does not contain element. */ -@Deprecated("Collection and element have incompatible types. Upcast element to Any? if you're sure.", ReplaceWith("indexOf(element as Any?)")) +@Deprecated("Collection and element have incompatible types. Upcast element to Any? if you're sure.", ReplaceWith("indexOf(element as T)")) @kotlin.jvm.JvmName("indexOfAny") @kotlin.internal.LowPriorityInOverloadResolution @Suppress("NOTHING_TO_INLINE") public fun Iterable.indexOf(element: T): Int { - return indexOf(element as Any?) + return indexOf(element as T) } /** * Returns first index of [element], or -1 if the collection does not contain element. */ -@Deprecated("List and element have incompatible types. Upcast element to Any? if you're sure.", ReplaceWith("indexOf(element as Any?)")) +@Deprecated("List and element have incompatible types. Upcast element to Any? if you're sure.", ReplaceWith("indexOf(element as T)")) @kotlin.jvm.JvmName("indexOfAny") @kotlin.internal.LowPriorityInOverloadResolution @Suppress("NOTHING_TO_INLINE") public fun List.indexOf(element: T): Int { - return indexOf(element as Any?) + return indexOf(element as T) } /** @@ -461,23 +461,23 @@ public fun <@kotlin.internal.OnlyInputTypes T> List.lastIndexOf(element: T): /** * Returns last index of [element], or -1 if the collection does not contain element. */ -@Deprecated("Collection and element have incompatible types. Upcast element to Any? if you're sure.", ReplaceWith("lastIndexOf(element as Any?)")) +@Deprecated("Collection and element have incompatible types. Upcast element to Any? if you're sure.", ReplaceWith("lastIndexOf(element as T)")) @kotlin.jvm.JvmName("lastIndexOfAny") @kotlin.internal.LowPriorityInOverloadResolution @Suppress("NOTHING_TO_INLINE") public fun Iterable.lastIndexOf(element: T): Int { - return lastIndexOf(element as Any?) + return lastIndexOf(element as T) } /** * Returns last index of [element], or -1 if the collection does not contain element. */ -@Deprecated("List and element have incompatible types. Upcast element to Any? if you're sure.", ReplaceWith("lastIndexOf(element as Any?)")) +@Deprecated("List and element have incompatible types. Upcast element to Any? if you're sure.", ReplaceWith("lastIndexOf(element as T)")) @kotlin.jvm.JvmName("lastIndexOfAny") @kotlin.internal.LowPriorityInOverloadResolution @Suppress("NOTHING_TO_INLINE") public fun List.lastIndexOf(element: T): Int { - return lastIndexOf(element as Any?) + return lastIndexOf(element as T) } /** diff --git a/libraries/stdlib/src/generated/_Sequences.kt b/libraries/stdlib/src/generated/_Sequences.kt index 3551bc98375..14e2b45f9d8 100644 --- a/libraries/stdlib/src/generated/_Sequences.kt +++ b/libraries/stdlib/src/generated/_Sequences.kt @@ -22,11 +22,11 @@ public operator fun <@kotlin.internal.OnlyInputTypes T> Sequence.contains(ele /** * Returns `true` if [element] is found in the collection. */ -@Deprecated("Sequence and element have incompatible types. Upcast element to Any? if you're sure.", ReplaceWith("contains(element as Any?)")) +@Deprecated("Sequence and element have incompatible types. Upcast element to Any? if you're sure.", ReplaceWith("contains(element as T)")) @kotlin.jvm.JvmName("containsAny") @kotlin.internal.LowPriorityInOverloadResolution public operator fun Sequence.contains(element: T): Boolean { - return contains(element as Any?) + return contains(element as T) } /** @@ -146,12 +146,12 @@ public fun <@kotlin.internal.OnlyInputTypes T> Sequence.indexOf(element: T): /** * Returns first index of [element], or -1 if the collection does not contain element. */ -@Deprecated("Sequence and element have incompatible types. Upcast element to Any? if you're sure.", ReplaceWith("indexOf(element as Any?)")) +@Deprecated("Sequence and element have incompatible types. Upcast element to Any? if you're sure.", ReplaceWith("indexOf(element as T)")) @kotlin.jvm.JvmName("indexOfAny") @kotlin.internal.LowPriorityInOverloadResolution @Suppress("NOTHING_TO_INLINE") public fun Sequence.indexOf(element: T): Int { - return indexOf(element as Any?) + return indexOf(element as T) } /** @@ -239,12 +239,12 @@ public fun <@kotlin.internal.OnlyInputTypes T> Sequence.lastIndexOf(element: /** * Returns last index of [element], or -1 if the collection does not contain element. */ -@Deprecated("Sequence and element have incompatible types. Upcast element to Any? if you're sure.", ReplaceWith("lastIndexOf(element as Any?)")) +@Deprecated("Sequence and element have incompatible types. Upcast element to Any? if you're sure.", ReplaceWith("lastIndexOf(element as T)")) @kotlin.jvm.JvmName("lastIndexOfAny") @kotlin.internal.LowPriorityInOverloadResolution @Suppress("NOTHING_TO_INLINE") public fun Sequence.lastIndexOf(element: T): Int { - return lastIndexOf(element as Any?) + return lastIndexOf(element as T) } /** diff --git a/libraries/stdlib/src/kotlin/collections/MutableCollections.kt b/libraries/stdlib/src/kotlin/collections/MutableCollections.kt index adeda1dc826..e2ceb079ee9 100644 --- a/libraries/stdlib/src/kotlin/collections/MutableCollections.kt +++ b/libraries/stdlib/src/kotlin/collections/MutableCollections.kt @@ -35,10 +35,10 @@ public fun <@kotlin.internal.OnlyInputTypes T> MutableCollection.remove(e @Deprecated("Collection and element have incompatible types. Upcast element to Any? if you're sure.", ReplaceWith("remove(element as Any?)")) public inline fun MutableCollection.removeRaw(element: Any?): Boolean = remove(element) -@Deprecated("Collection and element have incompatible types. Upcast element to Any? if you're sure.", ReplaceWith("remove(element as Any?)")) +@Deprecated("Collection and element have incompatible types. Upcast element to Any? if you're sure.", ReplaceWith("remove(element as T)")) @kotlin.jvm.JvmName("removeAny") @kotlin.internal.LowPriorityInOverloadResolution -public fun MutableCollection.remove(element: Any?): Boolean = remove(element) +public fun MutableCollection.remove(element: T): Boolean = remove(element) /** * Removes all of this collection's elements that are also contained in the specified collection. @@ -102,17 +102,17 @@ public fun MutableList.remove(index: Int): E = removeAt(index) @Deprecated("Use property 'length' instead.", ReplaceWith("length")) public fun CharSequence.length(): Int = length -@Deprecated("Map and key have incompatible types. Upcast key to Any? if you're sure.", ReplaceWith("get(key as Any?)")) +@Deprecated("Map and key have incompatible types. Upcast key to Any? if you're sure.", ReplaceWith("get(key as K)")) @kotlin.internal.LowPriorityInOverloadResolution -public inline operator fun Map.get(key: Any?): V? = get(key) +public inline operator fun Map.get(key: K): V? = get(key) -@Deprecated("Map and key have incompatible types. Upcast key to Any? if you're sure.", ReplaceWith("containsKey(key as Any?)")) +@Deprecated("Map and key have incompatible types. Upcast key to Any? if you're sure.", ReplaceWith("containsKey(key as K)")) @kotlin.internal.LowPriorityInOverloadResolution -public inline fun Map.containsKey(key: Any?): Boolean = containsKey(key) +public inline fun Map.containsKey(key: K): Boolean = containsKey(key) -@Deprecated("Map and value have incompatible types. Upcast value to Any? if you're sure.", ReplaceWith("containsValue(value as Any?)")) +@Deprecated("Map and value have incompatible types. Upcast value to Any? if you're sure.", ReplaceWith("containsValue(value as V)")) @kotlin.internal.LowPriorityInOverloadResolution -public inline fun Map.containsValue(value: Any?): Boolean = containsValue(value as Any?) +public inline fun Map.containsValue(value: V): Boolean = containsValue(value as Any?) @Deprecated("Use property 'keys' instead.", ReplaceWith("keys")) public inline fun Map.keySet(): Set = keys diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Elements.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Elements.kt index abf4064f6ba..73504238c6e 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Elements.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Elements.kt @@ -34,7 +34,7 @@ fun elements(): List { only(Iterables, Sequences, ArraysOfObjects) doc { "Returns `true` if [element] is found in the collection." } returns("Boolean") - deprecate { f -> with(DocExtensions) { Deprecation("${f.collection.capitalize()} and element have incompatible types. Upcast element to Any? if you're sure.", "contains(element as Any?)") } } + deprecate { f -> with(DocExtensions) { Deprecation("${f.collection.capitalize()} and element have incompatible types. Upcast element to Any? if you're sure.", "contains(element as T)") } } annotations(""" @kotlin.jvm.JvmName("containsAny") @kotlin.internal.LowPriorityInOverloadResolution @@ -109,7 +109,7 @@ fun elements(): List { only(Iterables, Sequences, ArraysOfObjects, Lists) doc { "Returns first index of [element], or -1 if the collection does not contain element." } returns("Int") - deprecate { f -> with(DocExtensions) { Deprecation("${f.collection.capitalize()} and element have incompatible types. Upcast element to Any? if you're sure.", "indexOf(element as Any?)") } } + deprecate { f -> with(DocExtensions) { Deprecation("${f.collection.capitalize()} and element have incompatible types. Upcast element to Any? if you're sure.", "indexOf(element as T)") } } annotations(""" @kotlin.jvm.JvmName("indexOfAny") @kotlin.internal.LowPriorityInOverloadResolution @@ -187,7 +187,7 @@ fun elements(): List { only(Iterables, Sequences, ArraysOfObjects, Lists) doc { "Returns last index of [element], or -1 if the collection does not contain element." } returns("Int") - deprecate { f -> with(DocExtensions) { Deprecation("${f.collection.capitalize()} and element have incompatible types. Upcast element to Any? if you're sure.", "lastIndexOf(element as Any?)") } } + deprecate { f -> with(DocExtensions) { Deprecation("${f.collection.capitalize()} and element have incompatible types. Upcast element to Any? if you're sure.", "lastIndexOf(element as T)") } } annotations(""" @kotlin.jvm.JvmName("lastIndexOfAny") @kotlin.internal.LowPriorityInOverloadResolution