diff --git a/libraries/stdlib/common/src/generated/_Arrays.kt b/libraries/stdlib/common/src/generated/_Arrays.kt index 905b65a5176..1830c89b596 100644 --- a/libraries/stdlib/common/src/generated/_Arrays.kt +++ b/libraries/stdlib/common/src/generated/_Arrays.kt @@ -6339,48 +6339,111 @@ public expect fun BooleanArray.copyOfRange(fromIndex: Int, toIndex: Int): Boolea public expect fun CharArray.copyOfRange(fromIndex: Int, toIndex: Int): CharArray /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ +@SinceKotlin("1.3") public expect fun Array.fill(element: T, fromIndex: Int = 0, toIndex: Int = size): Unit /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ +@SinceKotlin("1.3") public expect fun ByteArray.fill(element: Byte, fromIndex: Int = 0, toIndex: Int = size): Unit /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ +@SinceKotlin("1.3") public expect fun ShortArray.fill(element: Short, fromIndex: Int = 0, toIndex: Int = size): Unit /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ +@SinceKotlin("1.3") public expect fun IntArray.fill(element: Int, fromIndex: Int = 0, toIndex: Int = size): Unit /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ +@SinceKotlin("1.3") public expect fun LongArray.fill(element: Long, fromIndex: Int = 0, toIndex: Int = size): Unit /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ +@SinceKotlin("1.3") public expect fun FloatArray.fill(element: Float, fromIndex: Int = 0, toIndex: Int = size): Unit /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ +@SinceKotlin("1.3") public expect fun DoubleArray.fill(element: Double, fromIndex: Int = 0, toIndex: Int = size): Unit /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ +@SinceKotlin("1.3") public expect fun BooleanArray.fill(element: Boolean, fromIndex: Int = 0, toIndex: Int = size): Unit /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ +@SinceKotlin("1.3") public expect fun CharArray.fill(element: Char, fromIndex: Int = 0, toIndex: Int = size): Unit /** diff --git a/libraries/stdlib/common/src/generated/_UArrays.kt b/libraries/stdlib/common/src/generated/_UArrays.kt index fe0d0186ed4..f20664f407a 100644 --- a/libraries/stdlib/common/src/generated/_UArrays.kt +++ b/libraries/stdlib/common/src/generated/_UArrays.kt @@ -3231,32 +3231,64 @@ public inline fun UShortArray.copyOfRange(fromIndex: Int, toIndex: Int): UShortA } /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ @SinceKotlin("1.3") @ExperimentalUnsignedTypes -public expect fun UIntArray.fill(element: UInt, fromIndex: Int = 0, toIndex: Int = size): Unit +public fun UIntArray.fill(element: UInt, fromIndex: Int = 0, toIndex: Int = size): Unit { + storage.fill(element.toInt(), fromIndex, toIndex) +} /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ @SinceKotlin("1.3") @ExperimentalUnsignedTypes -public expect fun ULongArray.fill(element: ULong, fromIndex: Int = 0, toIndex: Int = size): Unit +public fun ULongArray.fill(element: ULong, fromIndex: Int = 0, toIndex: Int = size): Unit { + storage.fill(element.toLong(), fromIndex, toIndex) +} /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ @SinceKotlin("1.3") @ExperimentalUnsignedTypes -public expect fun UByteArray.fill(element: UByte, fromIndex: Int = 0, toIndex: Int = size): Unit +public fun UByteArray.fill(element: UByte, fromIndex: Int = 0, toIndex: Int = size): Unit { + storage.fill(element.toByte(), fromIndex, toIndex) +} /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ @SinceKotlin("1.3") @ExperimentalUnsignedTypes -public expect fun UShortArray.fill(element: UShort, fromIndex: Int = 0, toIndex: Int = size): Unit +public fun UShortArray.fill(element: UShort, fromIndex: Int = 0, toIndex: Int = size): Unit { + storage.fill(element.toShort(), fromIndex, toIndex) +} /** * Returns the range of valid indices for the array. diff --git a/libraries/stdlib/js-ir/src/generated/_ArraysJs.kt b/libraries/stdlib/js-ir/src/generated/_ArraysJs.kt index af1f91fb7cd..1eb3aab8283 100644 --- a/libraries/stdlib/js-ir/src/generated/_ArraysJs.kt +++ b/libraries/stdlib/js-ir/src/generated/_ArraysJs.kt @@ -1024,137 +1024,146 @@ public actual fun CharArray.copyOfRange(fromIndex: Int, toIndex: Int): CharArray } /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ +@SinceKotlin("1.3") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun Array.fill(element: T, fromIndex: Int = 0, toIndex: Int = size): Unit { - if (fromIndex !in 0..size) { - throw IndexOutOfBoundsException("fromIndex $fromIndex out of range [0, $size]") - } - if (toIndex > size) { - throw IndexOutOfBoundsException("toIndex $toIndex out of range [$fromIndex, $size]") - } - require(fromIndex <= toIndex) { "fromIndex($fromIndex) > toIndex($toIndex)" } + AbstractList.checkRangeIndexes(fromIndex, toIndex, size) this.asDynamic().fill(element, fromIndex, toIndex); } /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ +@SinceKotlin("1.3") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun ByteArray.fill(element: Byte, fromIndex: Int = 0, toIndex: Int = size): Unit { - if (fromIndex !in 0..size) { - throw IndexOutOfBoundsException("fromIndex $fromIndex out of range [0, $size]") - } - if (toIndex > size) { - throw IndexOutOfBoundsException("toIndex $toIndex out of range [$fromIndex, $size]") - } - require(fromIndex <= toIndex) { "fromIndex($fromIndex) > toIndex($toIndex)" } + AbstractList.checkRangeIndexes(fromIndex, toIndex, size) this.asDynamic().fill(element, fromIndex, toIndex); } /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ +@SinceKotlin("1.3") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun ShortArray.fill(element: Short, fromIndex: Int = 0, toIndex: Int = size): Unit { - if (fromIndex !in 0..size) { - throw IndexOutOfBoundsException("fromIndex $fromIndex out of range [0, $size]") - } - if (toIndex > size) { - throw IndexOutOfBoundsException("toIndex $toIndex out of range [$fromIndex, $size]") - } - require(fromIndex <= toIndex) { "fromIndex($fromIndex) > toIndex($toIndex)" } + AbstractList.checkRangeIndexes(fromIndex, toIndex, size) this.asDynamic().fill(element, fromIndex, toIndex); } /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ +@SinceKotlin("1.3") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun IntArray.fill(element: Int, fromIndex: Int = 0, toIndex: Int = size): Unit { - if (fromIndex !in 0..size) { - throw IndexOutOfBoundsException("fromIndex $fromIndex out of range [0, $size]") - } - if (toIndex > size) { - throw IndexOutOfBoundsException("toIndex $toIndex out of range [$fromIndex, $size]") - } - require(fromIndex <= toIndex) { "fromIndex($fromIndex) > toIndex($toIndex)" } + AbstractList.checkRangeIndexes(fromIndex, toIndex, size) this.asDynamic().fill(element, fromIndex, toIndex); } /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ +@SinceKotlin("1.3") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun LongArray.fill(element: Long, fromIndex: Int = 0, toIndex: Int = size): Unit { - if (fromIndex !in 0..size) { - throw IndexOutOfBoundsException("fromIndex $fromIndex out of range [0, $size]") - } - if (toIndex > size) { - throw IndexOutOfBoundsException("toIndex $toIndex out of range [$fromIndex, $size]") - } - require(fromIndex <= toIndex) { "fromIndex($fromIndex) > toIndex($toIndex)" } + AbstractList.checkRangeIndexes(fromIndex, toIndex, size) this.asDynamic().fill(element, fromIndex, toIndex); } /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ +@SinceKotlin("1.3") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun FloatArray.fill(element: Float, fromIndex: Int = 0, toIndex: Int = size): Unit { - if (fromIndex !in 0..size) { - throw IndexOutOfBoundsException("fromIndex $fromIndex out of range [0, $size]") - } - if (toIndex > size) { - throw IndexOutOfBoundsException("toIndex $toIndex out of range [$fromIndex, $size]") - } - require(fromIndex <= toIndex) { "fromIndex($fromIndex) > toIndex($toIndex)" } + AbstractList.checkRangeIndexes(fromIndex, toIndex, size) this.asDynamic().fill(element, fromIndex, toIndex); } /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ +@SinceKotlin("1.3") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun DoubleArray.fill(element: Double, fromIndex: Int = 0, toIndex: Int = size): Unit { - if (fromIndex !in 0..size) { - throw IndexOutOfBoundsException("fromIndex $fromIndex out of range [0, $size]") - } - if (toIndex > size) { - throw IndexOutOfBoundsException("toIndex $toIndex out of range [$fromIndex, $size]") - } - require(fromIndex <= toIndex) { "fromIndex($fromIndex) > toIndex($toIndex)" } + AbstractList.checkRangeIndexes(fromIndex, toIndex, size) this.asDynamic().fill(element, fromIndex, toIndex); } /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ +@SinceKotlin("1.3") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun BooleanArray.fill(element: Boolean, fromIndex: Int = 0, toIndex: Int = size): Unit { - if (fromIndex !in 0..size) { - throw IndexOutOfBoundsException("fromIndex $fromIndex out of range [0, $size]") - } - if (toIndex > size) { - throw IndexOutOfBoundsException("toIndex $toIndex out of range [$fromIndex, $size]") - } - require(fromIndex <= toIndex) { "fromIndex($fromIndex) > toIndex($toIndex)" } + AbstractList.checkRangeIndexes(fromIndex, toIndex, size) this.asDynamic().fill(element, fromIndex, toIndex); } /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ +@SinceKotlin("1.3") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun CharArray.fill(element: Char, fromIndex: Int = 0, toIndex: Int = size): Unit { - if (fromIndex !in 0..size) { - throw IndexOutOfBoundsException("fromIndex $fromIndex out of range [0, $size]") - } - if (toIndex > size) { - throw IndexOutOfBoundsException("toIndex $toIndex out of range [$fromIndex, $size]") - } - require(fromIndex <= toIndex) { "fromIndex($fromIndex) > toIndex($toIndex)" } + AbstractList.checkRangeIndexes(fromIndex, toIndex, size) this.asDynamic().fill(element, fromIndex, toIndex); } diff --git a/libraries/stdlib/js-ir/src/generated/_UArraysJs.kt b/libraries/stdlib/js-ir/src/generated/_UArraysJs.kt index ebdf41a5445..0260b62541d 100644 --- a/libraries/stdlib/js-ir/src/generated/_UArraysJs.kt +++ b/libraries/stdlib/js-ir/src/generated/_UArraysJs.kt @@ -158,43 +158,3 @@ public actual fun UShortArray.asList(): List { } } -/** - * Fills original array with the provided value. - */ -@SinceKotlin("1.3") -@ExperimentalUnsignedTypes -@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") -public actual fun UIntArray.fill(element: UInt, fromIndex: Int = 0, toIndex: Int = size): Unit { - storage.fill(element.toInt(), fromIndex, toIndex) -} - -/** - * Fills original array with the provided value. - */ -@SinceKotlin("1.3") -@ExperimentalUnsignedTypes -@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") -public actual fun ULongArray.fill(element: ULong, fromIndex: Int = 0, toIndex: Int = size): Unit { - storage.fill(element.toLong(), fromIndex, toIndex) -} - -/** - * Fills original array with the provided value. - */ -@SinceKotlin("1.3") -@ExperimentalUnsignedTypes -@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") -public actual fun UByteArray.fill(element: UByte, fromIndex: Int = 0, toIndex: Int = size): Unit { - storage.fill(element.toByte(), fromIndex, toIndex) -} - -/** - * Fills original array with the provided value. - */ -@SinceKotlin("1.3") -@ExperimentalUnsignedTypes -@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") -public actual fun UShortArray.fill(element: UShort, fromIndex: Int = 0, toIndex: Int = size): Unit { - storage.fill(element.toShort(), fromIndex, toIndex) -} - diff --git a/libraries/stdlib/js/src/generated/_ArraysJs.kt b/libraries/stdlib/js/src/generated/_ArraysJs.kt index 4e3ea15c2ef..f0aac52d0a2 100644 --- a/libraries/stdlib/js/src/generated/_ArraysJs.kt +++ b/libraries/stdlib/js/src/generated/_ArraysJs.kt @@ -1054,137 +1054,146 @@ public actual fun CharArray.copyOfRange(fromIndex: Int, toIndex: Int): CharArray } /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ +@SinceKotlin("1.3") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun Array.fill(element: T, fromIndex: Int = 0, toIndex: Int = size): Unit { - if (fromIndex !in 0..size) { - throw IndexOutOfBoundsException("fromIndex $fromIndex out of range [0, $size]") - } - if (toIndex > size) { - throw IndexOutOfBoundsException("toIndex $toIndex out of range [$fromIndex, $size]") - } - require(fromIndex <= toIndex) { "fromIndex($fromIndex) > toIndex($toIndex)" } + AbstractList.checkRangeIndexes(fromIndex, toIndex, size) this.asDynamic().fill(element, fromIndex, toIndex); } /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ +@SinceKotlin("1.3") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun ByteArray.fill(element: Byte, fromIndex: Int = 0, toIndex: Int = size): Unit { - if (fromIndex !in 0..size) { - throw IndexOutOfBoundsException("fromIndex $fromIndex out of range [0, $size]") - } - if (toIndex > size) { - throw IndexOutOfBoundsException("toIndex $toIndex out of range [$fromIndex, $size]") - } - require(fromIndex <= toIndex) { "fromIndex($fromIndex) > toIndex($toIndex)" } + AbstractList.checkRangeIndexes(fromIndex, toIndex, size) this.asDynamic().fill(element, fromIndex, toIndex); } /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ +@SinceKotlin("1.3") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun ShortArray.fill(element: Short, fromIndex: Int = 0, toIndex: Int = size): Unit { - if (fromIndex !in 0..size) { - throw IndexOutOfBoundsException("fromIndex $fromIndex out of range [0, $size]") - } - if (toIndex > size) { - throw IndexOutOfBoundsException("toIndex $toIndex out of range [$fromIndex, $size]") - } - require(fromIndex <= toIndex) { "fromIndex($fromIndex) > toIndex($toIndex)" } + AbstractList.checkRangeIndexes(fromIndex, toIndex, size) this.asDynamic().fill(element, fromIndex, toIndex); } /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ +@SinceKotlin("1.3") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun IntArray.fill(element: Int, fromIndex: Int = 0, toIndex: Int = size): Unit { - if (fromIndex !in 0..size) { - throw IndexOutOfBoundsException("fromIndex $fromIndex out of range [0, $size]") - } - if (toIndex > size) { - throw IndexOutOfBoundsException("toIndex $toIndex out of range [$fromIndex, $size]") - } - require(fromIndex <= toIndex) { "fromIndex($fromIndex) > toIndex($toIndex)" } + AbstractList.checkRangeIndexes(fromIndex, toIndex, size) this.asDynamic().fill(element, fromIndex, toIndex); } /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ +@SinceKotlin("1.3") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun LongArray.fill(element: Long, fromIndex: Int = 0, toIndex: Int = size): Unit { - if (fromIndex !in 0..size) { - throw IndexOutOfBoundsException("fromIndex $fromIndex out of range [0, $size]") - } - if (toIndex > size) { - throw IndexOutOfBoundsException("toIndex $toIndex out of range [$fromIndex, $size]") - } - require(fromIndex <= toIndex) { "fromIndex($fromIndex) > toIndex($toIndex)" } + AbstractList.checkRangeIndexes(fromIndex, toIndex, size) this.asDynamic().fill(element, fromIndex, toIndex); } /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ +@SinceKotlin("1.3") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun FloatArray.fill(element: Float, fromIndex: Int = 0, toIndex: Int = size): Unit { - if (fromIndex !in 0..size) { - throw IndexOutOfBoundsException("fromIndex $fromIndex out of range [0, $size]") - } - if (toIndex > size) { - throw IndexOutOfBoundsException("toIndex $toIndex out of range [$fromIndex, $size]") - } - require(fromIndex <= toIndex) { "fromIndex($fromIndex) > toIndex($toIndex)" } + AbstractList.checkRangeIndexes(fromIndex, toIndex, size) this.asDynamic().fill(element, fromIndex, toIndex); } /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ +@SinceKotlin("1.3") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun DoubleArray.fill(element: Double, fromIndex: Int = 0, toIndex: Int = size): Unit { - if (fromIndex !in 0..size) { - throw IndexOutOfBoundsException("fromIndex $fromIndex out of range [0, $size]") - } - if (toIndex > size) { - throw IndexOutOfBoundsException("toIndex $toIndex out of range [$fromIndex, $size]") - } - require(fromIndex <= toIndex) { "fromIndex($fromIndex) > toIndex($toIndex)" } + AbstractList.checkRangeIndexes(fromIndex, toIndex, size) this.asDynamic().fill(element, fromIndex, toIndex); } /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ +@SinceKotlin("1.3") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun BooleanArray.fill(element: Boolean, fromIndex: Int = 0, toIndex: Int = size): Unit { - if (fromIndex !in 0..size) { - throw IndexOutOfBoundsException("fromIndex $fromIndex out of range [0, $size]") - } - if (toIndex > size) { - throw IndexOutOfBoundsException("toIndex $toIndex out of range [$fromIndex, $size]") - } - require(fromIndex <= toIndex) { "fromIndex($fromIndex) > toIndex($toIndex)" } + AbstractList.checkRangeIndexes(fromIndex, toIndex, size) this.asDynamic().fill(element, fromIndex, toIndex); } /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ +@SinceKotlin("1.3") @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun CharArray.fill(element: Char, fromIndex: Int = 0, toIndex: Int = size): Unit { - if (fromIndex !in 0..size) { - throw IndexOutOfBoundsException("fromIndex $fromIndex out of range [0, $size]") - } - if (toIndex > size) { - throw IndexOutOfBoundsException("toIndex $toIndex out of range [$fromIndex, $size]") - } - require(fromIndex <= toIndex) { "fromIndex($fromIndex) > toIndex($toIndex)" } + AbstractList.checkRangeIndexes(fromIndex, toIndex, size) this.asDynamic().fill(element, fromIndex, toIndex); } diff --git a/libraries/stdlib/js/src/generated/_UArraysJs.kt b/libraries/stdlib/js/src/generated/_UArraysJs.kt index ebdf41a5445..0260b62541d 100644 --- a/libraries/stdlib/js/src/generated/_UArraysJs.kt +++ b/libraries/stdlib/js/src/generated/_UArraysJs.kt @@ -158,43 +158,3 @@ public actual fun UShortArray.asList(): List { } } -/** - * Fills original array with the provided value. - */ -@SinceKotlin("1.3") -@ExperimentalUnsignedTypes -@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") -public actual fun UIntArray.fill(element: UInt, fromIndex: Int = 0, toIndex: Int = size): Unit { - storage.fill(element.toInt(), fromIndex, toIndex) -} - -/** - * Fills original array with the provided value. - */ -@SinceKotlin("1.3") -@ExperimentalUnsignedTypes -@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") -public actual fun ULongArray.fill(element: ULong, fromIndex: Int = 0, toIndex: Int = size): Unit { - storage.fill(element.toLong(), fromIndex, toIndex) -} - -/** - * Fills original array with the provided value. - */ -@SinceKotlin("1.3") -@ExperimentalUnsignedTypes -@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") -public actual fun UByteArray.fill(element: UByte, fromIndex: Int = 0, toIndex: Int = size): Unit { - storage.fill(element.toByte(), fromIndex, toIndex) -} - -/** - * Fills original array with the provided value. - */ -@SinceKotlin("1.3") -@ExperimentalUnsignedTypes -@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") -public actual fun UShortArray.fill(element: UShort, fromIndex: Int = 0, toIndex: Int = size): Unit { - storage.fill(element.toShort(), fromIndex, toIndex) -} - diff --git a/libraries/stdlib/jvm/src/generated/_ArraysJvm.kt b/libraries/stdlib/jvm/src/generated/_ArraysJvm.kt index d40e7c48a2a..363c781668e 100644 --- a/libraries/stdlib/jvm/src/generated/_ArraysJvm.kt +++ b/libraries/stdlib/jvm/src/generated/_ArraysJvm.kt @@ -1377,7 +1377,13 @@ internal fun CharArray.copyOfRangeImpl(fromIndex: Int, toIndex: Int): CharArray } /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun Array.fill(element: T, fromIndex: Int = 0, toIndex: Int = size): Unit { @@ -1385,7 +1391,13 @@ public actual fun Array.fill(element: T, fromIndex: Int = 0, toIndex: Int } /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun ByteArray.fill(element: Byte, fromIndex: Int = 0, toIndex: Int = size): Unit { @@ -1393,7 +1405,13 @@ public actual fun ByteArray.fill(element: Byte, fromIndex: Int = 0, toIndex: Int } /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun ShortArray.fill(element: Short, fromIndex: Int = 0, toIndex: Int = size): Unit { @@ -1401,7 +1419,13 @@ public actual fun ShortArray.fill(element: Short, fromIndex: Int = 0, toIndex: I } /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun IntArray.fill(element: Int, fromIndex: Int = 0, toIndex: Int = size): Unit { @@ -1409,7 +1433,13 @@ public actual fun IntArray.fill(element: Int, fromIndex: Int = 0, toIndex: Int = } /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun LongArray.fill(element: Long, fromIndex: Int = 0, toIndex: Int = size): Unit { @@ -1417,7 +1447,13 @@ public actual fun LongArray.fill(element: Long, fromIndex: Int = 0, toIndex: Int } /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun FloatArray.fill(element: Float, fromIndex: Int = 0, toIndex: Int = size): Unit { @@ -1425,7 +1461,13 @@ public actual fun FloatArray.fill(element: Float, fromIndex: Int = 0, toIndex: I } /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun DoubleArray.fill(element: Double, fromIndex: Int = 0, toIndex: Int = size): Unit { @@ -1433,7 +1475,13 @@ public actual fun DoubleArray.fill(element: Double, fromIndex: Int = 0, toIndex: } /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun BooleanArray.fill(element: Boolean, fromIndex: Int = 0, toIndex: Int = size): Unit { @@ -1441,7 +1489,13 @@ public actual fun BooleanArray.fill(element: Boolean, fromIndex: Int = 0, toInde } /** - * Fills original array with the provided value. + * Fills this array or its subrange with the specified [element] value. + * + * @param fromIndex the start of the range (inclusive), 0 by default. + * @param toIndex the end of the range (exclusive), size of this array by default. + * + * @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + * @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. */ @Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") public actual fun CharArray.fill(element: Char, fromIndex: Int = 0, toIndex: Int = size): Unit { diff --git a/libraries/stdlib/jvm/src/generated/_UArraysJvm.kt b/libraries/stdlib/jvm/src/generated/_UArraysJvm.kt index 734ba388539..8cbd6e77a3f 100644 --- a/libraries/stdlib/jvm/src/generated/_UArraysJvm.kt +++ b/libraries/stdlib/jvm/src/generated/_UArraysJvm.kt @@ -257,43 +257,3 @@ public fun UShortArray.binarySearch(element: UShort, fromIndex: Int = 0, toIndex return -(low + 1) // key not found } -/** - * Fills original array with the provided value. - */ -@SinceKotlin("1.3") -@ExperimentalUnsignedTypes -@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") -public actual fun UIntArray.fill(element: UInt, fromIndex: Int = 0, toIndex: Int = size): Unit { - storage.fill(element.toInt(), fromIndex, toIndex) -} - -/** - * Fills original array with the provided value. - */ -@SinceKotlin("1.3") -@ExperimentalUnsignedTypes -@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") -public actual fun ULongArray.fill(element: ULong, fromIndex: Int = 0, toIndex: Int = size): Unit { - storage.fill(element.toLong(), fromIndex, toIndex) -} - -/** - * Fills original array with the provided value. - */ -@SinceKotlin("1.3") -@ExperimentalUnsignedTypes -@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") -public actual fun UByteArray.fill(element: UByte, fromIndex: Int = 0, toIndex: Int = size): Unit { - storage.fill(element.toByte(), fromIndex, toIndex) -} - -/** - * Fills original array with the provided value. - */ -@SinceKotlin("1.3") -@ExperimentalUnsignedTypes -@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") -public actual fun UShortArray.fill(element: UShort, fromIndex: Int = 0, toIndex: Int = size): Unit { - storage.fill(element.toShort(), fromIndex, toIndex) -} - diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Arrays.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Arrays.kt index 4244a4d422b..a6764a95f14 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Arrays.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Arrays.kt @@ -1275,47 +1275,54 @@ object ArrayOps : TemplateGroupBase() { val f_fill = fn("fill(element: T, fromIndex: Int = 0, toIndex: Int = size)") { include(InvariantArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned) } builder { - doc { "Fills original array with the provided value." } + doc { + """ + Fills this array or its subrange with the specified [element] value. + + @param fromIndex the start of the range (inclusive), 0 by default. + @param toIndex the end of the range (exclusive), size of this array by default. + + @throws IndexOutOfBoundsException if [fromIndex] is less than zero or [toIndex] is greater than the size of this array. + @throws IllegalArgumentException if [fromIndex] is greater than [toIndex]. + """ + } returns("Unit") - on(Platform.JVM) { - suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") - body { - """ - java.util.Arrays.fill(this, fromIndex, toIndex, element) - """ - } - } - on(Platform.JS) { - suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") - body { - """ - if (fromIndex !in 0..size) { - throw IndexOutOfBoundsException("fromIndex ${'$'}fromIndex out of range [0, ${'$'}size]") - } - if (toIndex > size) { - throw IndexOutOfBoundsException("toIndex ${'$'}toIndex out of range [${'$'}fromIndex, ${'$'}size]") - } - require(fromIndex <= toIndex) { "fromIndex(${'$'}fromIndex) > toIndex(${'$'}toIndex)" } - this.asDynamic().fill(element, fromIndex, toIndex); - """ - } - } - on(Platform.Native) { - suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") - body { - """ - arrayFill(this, element, fromIndex, toIndex) - """ - } - } - specialFor(ArraysOfUnsigned) { val signedPrimitiveName = primitive!!.name.drop(1) body { "storage.fill(element.to$signedPrimitiveName(), fromIndex, toIndex)" } } + + specialFor(InvariantArraysOfObjects, ArraysOfPrimitives) { + on(Platform.JVM) { + suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") + body { + "java.util.Arrays.fill(this, fromIndex, toIndex, element)" + } + } + on(Platform.JS) { + suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") + since("1.3") + body { + """ + AbstractList.checkRangeIndexes(fromIndex, toIndex, size) + this.asDynamic().fill(element, fromIndex, toIndex); + """ + } + } + on(Platform.Native) { + suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") + since("1.3") + body { + "arrayFill(this, fromIndex, toIndex, element)" + } + } + on(Platform.Common) { + since("1.3") + } + } } val f_binarySearch = fn("binarySearch(element: T, fromIndex: Int = 0, toIndex: Int = size)") {