stdlib: Suppress/fix warnings in stdlib
This patch fixes redundant safe calls/casts/type projections and suppresses some casts which are actually safe but reported as unsafe.
This commit is contained in:
@@ -5058,6 +5058,7 @@ public inline fun <T> Array<out T>.single(predicate: (T) -> Boolean): T {
|
||||
}
|
||||
}
|
||||
if (!found) throw NoSuchElementException("Array contains no element matching the predicate.")
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return single as T
|
||||
}
|
||||
|
||||
@@ -10390,7 +10391,7 @@ public inline fun CharArray.copyOf(): CharArray {
|
||||
*/
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <T> Array<T>.copyOf(newSize: Int): Array<T?> {
|
||||
return copyOfNulls(newSize) as Array<T?>
|
||||
return copyOfNulls(newSize)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -11443,8 +11444,6 @@ public inline fun <T> Array<out T>.subarrayContentToString(offset: Int, length:
|
||||
public infix fun <T> Array<out T>.contentDeepEquals(other: Array<out T>): Boolean {
|
||||
if (this === other)
|
||||
return true
|
||||
if (other == null)
|
||||
return false
|
||||
|
||||
if (size != other.size)
|
||||
return false
|
||||
@@ -11758,7 +11757,7 @@ public fun <T> Array<out T>.contentHashCode(): Int {
|
||||
public fun ByteArray.contentHashCode(): Int {
|
||||
var result = 1
|
||||
for (element in this)
|
||||
result = 31 * result + (element?.hashCode() ?: 0)
|
||||
result = 31 * result + element.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -11769,7 +11768,7 @@ public fun ByteArray.contentHashCode(): Int {
|
||||
public fun ShortArray.contentHashCode(): Int {
|
||||
var result = 1
|
||||
for (element in this)
|
||||
result = 31 * result + (element?.hashCode() ?: 0)
|
||||
result = 31 * result + element.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -11780,7 +11779,7 @@ public fun ShortArray.contentHashCode(): Int {
|
||||
public fun IntArray.contentHashCode(): Int {
|
||||
var result = 1
|
||||
for (element in this)
|
||||
result = 31 * result + (element?.hashCode() ?: 0)
|
||||
result = 31 * result + element.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -11791,7 +11790,7 @@ public fun IntArray.contentHashCode(): Int {
|
||||
public fun LongArray.contentHashCode(): Int {
|
||||
var result = 1
|
||||
for (element in this)
|
||||
result = 31 * result + (element?.hashCode() ?: 0)
|
||||
result = 31 * result + element.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -11802,7 +11801,7 @@ public fun LongArray.contentHashCode(): Int {
|
||||
public fun FloatArray.contentHashCode(): Int {
|
||||
var result = 1
|
||||
for (element in this)
|
||||
result = 31 * result + (element?.hashCode() ?: 0)
|
||||
result = 31 * result + element.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -11813,7 +11812,7 @@ public fun FloatArray.contentHashCode(): Int {
|
||||
public fun DoubleArray.contentHashCode(): Int {
|
||||
var result = 1
|
||||
for (element in this)
|
||||
result = 31 * result + (element?.hashCode() ?: 0)
|
||||
result = 31 * result + element.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -11824,7 +11823,7 @@ public fun DoubleArray.contentHashCode(): Int {
|
||||
public fun BooleanArray.contentHashCode(): Int {
|
||||
var result = 1
|
||||
for (element in this)
|
||||
result = 31 * result + (element?.hashCode() ?: 0)
|
||||
result = 31 * result + element.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -11835,7 +11834,7 @@ public fun BooleanArray.contentHashCode(): Int {
|
||||
public fun CharArray.contentHashCode(): Int {
|
||||
var result = 1
|
||||
for (element in this)
|
||||
result = 31 * result + (element?.hashCode() ?: 0)
|
||||
result = 31 * result + element.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ public abstract class AbstractIterator<T>: Iterator<T> {
|
||||
override fun next(): T {
|
||||
if (!hasNext()) throw NoSuchElementException()
|
||||
state = State.NotReady
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return nextValue as T
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ internal fun <E, T> collectionToArray(collection: Collection<E>, array: Array<T>
|
||||
}
|
||||
var i = 0
|
||||
for (v in collection) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
toArray[i] = v as T
|
||||
i++
|
||||
}
|
||||
|
||||
@@ -796,6 +796,7 @@ public inline fun <T> Iterable<T>.last(predicate: (T) -> Boolean): T {
|
||||
}
|
||||
}
|
||||
if (!found) throw NoSuchElementException("Collection contains no element matching the predicate.")
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return last as T
|
||||
}
|
||||
|
||||
@@ -929,6 +930,7 @@ public inline fun <T> Iterable<T>.single(predicate: (T) -> Boolean): T {
|
||||
}
|
||||
}
|
||||
if (!found) throw NoSuchElementException("Collection contains no element matching the predicate.")
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return single as T
|
||||
}
|
||||
|
||||
|
||||
@@ -109,6 +109,7 @@ public inline fun <T, K, R, M : MutableMap<in K, R>> Grouping<T, K>.aggregateTo(
|
||||
* @return a [Map] associating the key of each group with the result of accumulating the group elements.
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
public inline fun <T, K, R> Grouping<T, K>.fold(
|
||||
initialValueSelector: (key: K, element: T) -> R,
|
||||
operation: (key: K, accumulator: R, element: T) -> R
|
||||
@@ -137,6 +138,7 @@ public inline fun <T, K, R> Grouping<T, K>.fold(
|
||||
* @return the [destination] map associating the key of each group with the result of accumulating the group elements.
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
public inline fun <T, K, R, M : MutableMap<in K, R>> Grouping<T, K>.foldTo(
|
||||
destination: M,
|
||||
initialValueSelector: (key: K, element: T) -> R,
|
||||
@@ -157,6 +159,7 @@ public inline fun <T, K, R, M : MutableMap<in K, R>> Grouping<T, K>.foldTo(
|
||||
* @return a [Map] associating the key of each group with the result of accumulating the group elements.
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
public inline fun <T, K, R> Grouping<T, K>.fold(
|
||||
initialValue: R,
|
||||
operation: (accumulator: R, element: T) -> R
|
||||
@@ -179,6 +182,7 @@ public inline fun <T, K, R> Grouping<T, K>.fold(
|
||||
* @return the [destination] map associating the key of each group with the result of accumulating the group elements.
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
public inline fun <T, K, R, M : MutableMap<in K, R>> Grouping<T, K>.foldTo(
|
||||
destination: M,
|
||||
initialValue: R,
|
||||
@@ -202,6 +206,7 @@ public inline fun <T, K, R, M : MutableMap<in K, R>> Grouping<T, K>.foldTo(
|
||||
* @return a [Map] associating the key of each group with the result of accumulating the group elements.
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
public inline fun <S, T : S, K> Grouping<T, K>.reduce(
|
||||
operation: (key: K, accumulator: S, element: T) -> S
|
||||
): Map<K, S> =
|
||||
@@ -227,6 +232,7 @@ public inline fun <S, T : S, K> Grouping<T, K>.reduce(
|
||||
* @return the [destination] map associating the key of each group with the result of accumulating the group elements.
|
||||
*/
|
||||
@SinceKotlin("1.1")
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
public inline fun <S, T : S, K, M : MutableMap<in K, S>> Grouping<T, K>.reduceTo(
|
||||
destination: M,
|
||||
operation: (key: K, accumulator: S, element: T) -> S
|
||||
|
||||
@@ -45,7 +45,7 @@ class HashMap<K, V> private constructor(
|
||||
INITIAL_MAX_PROBE_DISTANCE,
|
||||
0)
|
||||
|
||||
constructor(m: Map<out K, out V>) : this(m.size) {
|
||||
constructor(m: Map<out K, V>) : this(m.size) {
|
||||
putAll(m)
|
||||
}
|
||||
|
||||
|
||||
@@ -224,6 +224,7 @@ internal inline fun <K, V> Map<K, V>.getOrElseNullable(key: K, defaultValue: ()
|
||||
if (value == null && !containsKey(key)) {
|
||||
return defaultValue()
|
||||
} else {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return value as V
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,6 +132,7 @@ internal class FilteringSequence<T>(private val sequence: Sequence<T>,
|
||||
val result = nextItem
|
||||
nextItem = null
|
||||
nextState = -1
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return result as T
|
||||
}
|
||||
|
||||
@@ -388,6 +389,7 @@ constructor(private val sequence: Sequence<T>,
|
||||
calcNext() // will change nextState
|
||||
if (nextState == 0)
|
||||
throw NoSuchElementException()
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val result = nextItem as T
|
||||
|
||||
// Clean next to avoid keeping reference on yielded instance
|
||||
@@ -474,6 +476,7 @@ constructor(private val sequence: Sequence<T>,
|
||||
drop()
|
||||
|
||||
if (dropState == 1) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val result = nextItem as T
|
||||
nextItem = null
|
||||
dropState = 0
|
||||
@@ -787,6 +790,7 @@ public inline fun <T> Sequence<T>.last(predicate: (T) -> Boolean): T {
|
||||
}
|
||||
}
|
||||
if (!found) throw NoSuchElementException("Sequence contains no element matching the predicate.")
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return last as T
|
||||
}
|
||||
|
||||
@@ -857,6 +861,7 @@ public inline fun <T> Sequence<T>.single(predicate: (T) -> Boolean): T {
|
||||
}
|
||||
}
|
||||
if (!found) throw NoSuchElementException("Sequence contains no element matching the predicate.")
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return single as T
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user