diff --git a/runtime/src/main/kotlin/kotlin/Arrays.kt b/runtime/src/main/kotlin/kotlin/Arrays.kt index 674ef622b15..3994571c58d 100644 --- a/runtime/src/main/kotlin/kotlin/Arrays.kt +++ b/runtime/src/main/kotlin/kotlin/Arrays.kt @@ -5058,6 +5058,7 @@ public inline fun Array.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 Array.copyOf(newSize: Int): Array { - return copyOfNulls(newSize) as Array + return copyOfNulls(newSize) } /** @@ -11443,8 +11444,6 @@ public inline fun Array.subarrayContentToString(offset: Int, length: public infix fun Array.contentDeepEquals(other: Array): Boolean { if (this === other) return true - if (other == null) - return false if (size != other.size) return false @@ -11758,7 +11757,7 @@ public fun Array.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 } diff --git a/runtime/src/main/kotlin/kotlin/collections/AbstractIterator.kt b/runtime/src/main/kotlin/kotlin/collections/AbstractIterator.kt index 98546d90f73..2a065439cd4 100644 --- a/runtime/src/main/kotlin/kotlin/collections/AbstractIterator.kt +++ b/runtime/src/main/kotlin/kotlin/collections/AbstractIterator.kt @@ -44,6 +44,7 @@ public abstract class AbstractIterator: Iterator { override fun next(): T { if (!hasNext()) throw NoSuchElementException() state = State.NotReady + @Suppress("UNCHECKED_CAST") return nextValue as T } diff --git a/runtime/src/main/kotlin/kotlin/collections/ArrayUtil.kt b/runtime/src/main/kotlin/kotlin/collections/ArrayUtil.kt index e1f0f2b2135..9ec53d2a6ee 100644 --- a/runtime/src/main/kotlin/kotlin/collections/ArrayUtil.kt +++ b/runtime/src/main/kotlin/kotlin/collections/ArrayUtil.kt @@ -69,6 +69,7 @@ internal fun collectionToArray(collection: Collection, array: Array } var i = 0 for (v in collection) { + @Suppress("UNCHECKED_CAST") toArray[i] = v as T i++ } diff --git a/runtime/src/main/kotlin/kotlin/collections/Collections.kt b/runtime/src/main/kotlin/kotlin/collections/Collections.kt index 557d19c70e2..f1e9b91d4c4 100644 --- a/runtime/src/main/kotlin/kotlin/collections/Collections.kt +++ b/runtime/src/main/kotlin/kotlin/collections/Collections.kt @@ -796,6 +796,7 @@ public inline fun Iterable.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 Iterable.single(predicate: (T) -> Boolean): T { } } if (!found) throw NoSuchElementException("Collection contains no element matching the predicate.") + @Suppress("UNCHECKED_CAST") return single as T } diff --git a/runtime/src/main/kotlin/kotlin/collections/Grouping.kt b/runtime/src/main/kotlin/kotlin/collections/Grouping.kt index b77f3b6587f..4eec8d79817 100644 --- a/runtime/src/main/kotlin/kotlin/collections/Grouping.kt +++ b/runtime/src/main/kotlin/kotlin/collections/Grouping.kt @@ -109,6 +109,7 @@ public inline fun > Grouping.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 Grouping.fold( initialValueSelector: (key: K, element: T) -> R, operation: (key: K, accumulator: R, element: T) -> R @@ -137,6 +138,7 @@ public inline fun Grouping.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 > Grouping.foldTo( destination: M, initialValueSelector: (key: K, element: T) -> R, @@ -157,6 +159,7 @@ public inline fun > Grouping.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 Grouping.fold( initialValue: R, operation: (accumulator: R, element: T) -> R @@ -179,6 +182,7 @@ public inline fun Grouping.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 > Grouping.foldTo( destination: M, initialValue: R, @@ -202,6 +206,7 @@ public inline fun > Grouping.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 Grouping.reduce( operation: (key: K, accumulator: S, element: T) -> S ): Map = @@ -227,6 +232,7 @@ public inline fun Grouping.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 > Grouping.reduceTo( destination: M, operation: (key: K, accumulator: S, element: T) -> S diff --git a/runtime/src/main/kotlin/kotlin/collections/HashMap.kt b/runtime/src/main/kotlin/kotlin/collections/HashMap.kt index f3a0fbdf6eb..5dc9e895ecb 100644 --- a/runtime/src/main/kotlin/kotlin/collections/HashMap.kt +++ b/runtime/src/main/kotlin/kotlin/collections/HashMap.kt @@ -45,7 +45,7 @@ class HashMap private constructor( INITIAL_MAX_PROBE_DISTANCE, 0) - constructor(m: Map) : this(m.size) { + constructor(m: Map) : this(m.size) { putAll(m) } diff --git a/runtime/src/main/kotlin/kotlin/collections/Maps.kt b/runtime/src/main/kotlin/kotlin/collections/Maps.kt index 7f4b89f7a04..7ea7221bdce 100644 --- a/runtime/src/main/kotlin/kotlin/collections/Maps.kt +++ b/runtime/src/main/kotlin/kotlin/collections/Maps.kt @@ -224,6 +224,7 @@ internal inline fun Map.getOrElseNullable(key: K, defaultValue: () if (value == null && !containsKey(key)) { return defaultValue() } else { + @Suppress("UNCHECKED_CAST") return value as V } } diff --git a/runtime/src/main/kotlin/kotlin/sequences/Sequences.kt b/runtime/src/main/kotlin/kotlin/sequences/Sequences.kt index 78ec20af21d..b018cec164c 100644 --- a/runtime/src/main/kotlin/kotlin/sequences/Sequences.kt +++ b/runtime/src/main/kotlin/kotlin/sequences/Sequences.kt @@ -132,6 +132,7 @@ internal class FilteringSequence(private val sequence: Sequence, val result = nextItem nextItem = null nextState = -1 + @Suppress("UNCHECKED_CAST") return result as T } @@ -388,6 +389,7 @@ constructor(private val sequence: Sequence, 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, drop() if (dropState == 1) { + @Suppress("UNCHECKED_CAST") val result = nextItem as T nextItem = null dropState = 0 @@ -787,6 +790,7 @@ public inline fun Sequence.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 Sequence.single(predicate: (T) -> Boolean): T { } } if (!found) throw NoSuchElementException("Sequence contains no element matching the predicate.") + @Suppress("UNCHECKED_CAST") return single as T }