Suppress UNCHECKED_CAST instead of CAST_NEVER_SUCCEEDS in several places

This is related to KT-6611 being fixed recently. Note that not all cases of
incorrect "cast never succeeds" were fixed
This commit is contained in:
Alexander Udalov
2016-07-12 21:32:35 +03:00
parent 13b0fda3c2
commit 8f33830f29
10 changed files with 15 additions and 17 deletions
+1 -1
View File
@@ -10973,7 +10973,7 @@ public fun <T : Any> Array<T?>.requireNoNulls(): Array<T> {
throw IllegalArgumentException("null element found in $this.")
}
}
@Suppress("CAST_NEVER_SUCCEEDS")
@Suppress("UNCHECKED_CAST")
return this as Array<T>
}
@@ -827,7 +827,7 @@ public fun <T : Comparable<T>> MutableList<T>.sortDescending(): Unit {
public fun <T : Comparable<T>> Iterable<T>.sorted(): List<T> {
if (this is Collection) {
if (size <= 1) return this.toList()
@Suppress("CAST_NEVER_SUCCEEDS")
@Suppress("UNCHECKED_CAST")
return (toTypedArray<Comparable<T>>() as Array<T>).apply { sort() }.asList()
}
return toMutableList().apply { sort() }
@@ -860,7 +860,7 @@ public fun <T : Comparable<T>> Iterable<T>.sortedDescending(): List<T> {
public fun <T> Iterable<T>.sortedWith(comparator: Comparator<in T>): List<T> {
if (this is Collection) {
if (size <= 1) return this.toList()
@Suppress("CAST_NEVER_SUCCEEDS")
@Suppress("UNCHECKED_CAST")
return (toTypedArray<Any?>() as Array<T>).apply { sortWith(comparator) }.asList()
}
return toMutableList().apply { sortWith(comparator) }
@@ -159,7 +159,7 @@ internal fun <T> List<T>.optimizeReadOnlyList() = when (size) {
private fun <T> Array<out T>.copyToArrayOfAny(isVarargs: Boolean): Array<Any?> =
if (isVarargs && this.javaClass == Array<Any?>::class.java)
// if the array came from varargs and already is array of Any, copying isn't required
@Suppress("CAST_NEVER_SUCCEEDS") (this as Array<Any?>)
@Suppress("UNCHECKED_CAST") (this as Array<Any?>)
else
Arrays.copyOf(this, this.size, Array<Any?>::class.java)