Document that array constructor throws RuntimeException on negative size

This commit is contained in:
Abduqodiri Qurbonzoda
2023-06-12 02:14:40 +03:00
committed by Space Team
parent 9f16daac02
commit da8f9fbd04
5 changed files with 95 additions and 7 deletions
@@ -25,6 +25,8 @@ public final class Array<T> {
*
* The function [init] is called for each array element sequentially starting from the first one.
* It should return the value for an array element given its index.
*
* @throws RuntimeException if the specified [size] is negative.
*/
@Suppress("TYPE_PARAMETER_AS_REIFIED", "WRONG_MODIFIER_TARGET")
public inline constructor(size: Int, init: (Int) -> T): this(size) {
@@ -17,10 +17,14 @@ import kotlin.native.internal.PointsTo
/**
* An array of bytes.
* @constructor Creates a new array of the specified [size], with all elements initialized to zero.
*/
@ExportTypeInfo("theByteArrayTypeInfo")
public final class ByteArray {
/**
* Creates a new array of the specified [size], with all elements initialized to zero.
*
* @throws RuntimeException if the specified [size] is negative.
*/
// Constructors are handled with compiler magic.
public constructor(@Suppress("UNUSED_PARAMETER") size: Int) {}
@@ -30,6 +34,8 @@ public final class ByteArray {
*
* The function [init] is called for each array element sequentially starting from the first one.
* It should return the value for an array element given its index.
*
* @throws RuntimeException if the specified [size] is negative.
*/
@Suppress("WRONG_MODIFIER_TARGET")
public inline constructor(size: Int, init: (Int) -> Byte): this(size) {
@@ -38,6 +44,7 @@ public final class ByteArray {
}
}
/** Returns the number of elements in the array. */
public val size: Int
get() = getArrayLength()
@@ -81,10 +88,14 @@ private class ByteIteratorImpl(val collection: ByteArray) : ByteIterator() {
/**
* An array of chars.
* @constructor Creates a new array of the specified [size], with all elements initialized to zero.
*/
@ExportTypeInfo("theCharArrayTypeInfo")
public final class CharArray {
/**
* Creates a new array of the specified [size], with all elements initialized to null char (`\u0000').
*
* @throws RuntimeException if the specified [size] is negative.
*/
// Constructors are handled with the compiler magic.
public constructor(@Suppress("UNUSED_PARAMETER") size: Int) {}
@@ -94,6 +105,8 @@ public final class CharArray {
*
* The function [init] is called for each array element sequentially starting from the first one.
* It should return the value for an array element given its index.
*
* @throws RuntimeException if the specified [size] is negative.
*/
@Suppress("WRONG_MODIFIER_TARGET")
public inline constructor(size: Int, init: (Int) -> Char): this(size) {
@@ -146,10 +159,14 @@ private class CharIteratorImpl(val collection: CharArray) : CharIterator() {
/**
* An array of shorts.
* @constructor Creates a new array of the specified [size], with all elements initialized to zero.
*/
@ExportTypeInfo("theShortArrayTypeInfo")
public final class ShortArray {
/**
* Creates a new array of the specified [size], with all elements initialized to zero.
*
* @throws RuntimeException if the specified [size] is negative.
*/
// Constructors are handled with the compiler magic.
public constructor(@Suppress("UNUSED_PARAMETER") size: Int) {}
@@ -159,6 +176,8 @@ public final class ShortArray {
*
* The function [init] is called for each array element sequentially starting from the first one.
* It should return the value for an array element given its index.
*
* @throws RuntimeException if the specified [size] is negative.
*/
@Suppress("WRONG_MODIFIER_TARGET")
public inline constructor(size: Int, init: (Int) -> Short): this(size) {
@@ -210,11 +229,15 @@ private class ShortIteratorImpl(val collection: ShortArray) : ShortIterator() {
}
/**
* An array of ints. When targeting the JVM, instances of this class are represented as `int[]`.
* @constructor Creates a new array of the specified [size], with all elements initialized to zero.
* An array of ints.
*/
@ExportTypeInfo("theIntArrayTypeInfo")
public final class IntArray {
/**
* Creates a new array of the specified [size], with all elements initialized to zero.
*
* @throws RuntimeException if the specified [size] is negative.
*/
// Constructors are handled with the compiler magic.
public constructor(@Suppress("UNUSED_PARAMETER") size: Int) {}
@@ -224,6 +247,8 @@ public final class IntArray {
*
* The function [init] is called for each array element sequentially starting from the first one.
* It should return the value for an array element given its index.
*
* @throws RuntimeException if the specified [size] is negative.
*/
@Suppress("WRONG_MODIFIER_TARGET")
public inline constructor(size: Int, init: (Int) -> Int): this(size) {
@@ -276,10 +301,14 @@ private class IntIteratorImpl(val collection: IntArray) : IntIterator() {
/**
* An array of longs.
* @constructor Creates a new array of the specified [size], with all elements initialized to zero.
*/
@ExportTypeInfo("theLongArrayTypeInfo")
public final class LongArray {
/**
* Creates a new array of the specified [size], with all elements initialized to zero.
*
* @throws RuntimeException if the specified [size] is negative.
*/
// Constructors are handled with the compiler magic.
public constructor(@Suppress("UNUSED_PARAMETER") size: Int) {}
@@ -289,6 +318,8 @@ public final class LongArray {
*
* The function [init] is called for each array element sequentially starting from the first one.
* It should return the value for an array element given its index.
*
* @throws RuntimeException if the specified [size] is negative.
*/
@Suppress("WRONG_MODIFIER_TARGET")
public inline constructor(size: Int, init: (Int) -> Long): this(size) {
@@ -341,10 +372,14 @@ private class LongIteratorImpl(val collection: LongArray) : LongIterator() {
/**
* An array of floats.
* @constructor Creates a new array of the specified [size], with all elements initialized to zero.
*/
@ExportTypeInfo("theFloatArrayTypeInfo")
public final class FloatArray {
/**
* Creates a new array of the specified [size], with all elements initialized to zero.
*
* @throws RuntimeException if the specified [size] is negative.
*/
// Constructors are handled with the compiler magic.
public constructor(@Suppress("UNUSED_PARAMETER") size: Int) {}
@@ -354,6 +389,8 @@ public final class FloatArray {
*
* The function [init] is called for each array element sequentially starting from the first one.
* It should return the value for an array element given its index.
*
* @throws RuntimeException if the specified [size] is negative.
*/
@Suppress("WRONG_MODIFIER_TARGET")
public inline constructor(size: Int, init: (Int) -> Float): this(size) {
@@ -404,8 +441,16 @@ private class FloatIteratorImpl(val collection: FloatArray) : FloatIterator() {
}
}
/**
* An array of doubles.
*/
@ExportTypeInfo("theDoubleArrayTypeInfo")
public final class DoubleArray {
/**
* Creates a new array of the specified [size], with all elements initialized to zero.
*
* @throws RuntimeException if the specified [size] is negative.
*/
// Constructors are handled with the compiler magic.
public constructor(@Suppress("UNUSED_PARAMETER") size: Int) {}
@@ -415,6 +460,8 @@ public final class DoubleArray {
*
* The function [init] is called for each array element sequentially starting from the first one.
* It should return the value for an array element given its index.
*
* @throws RuntimeException if the specified [size] is negative.
*/
@Suppress("WRONG_MODIFIER_TARGET")
public inline constructor(size: Int, init: (Int) -> Double): this(size) {
@@ -465,8 +512,16 @@ private class DoubleIteratorImpl(val collection: DoubleArray) : DoubleIterator()
}
}
/**
* An array of booleans.
*/
@ExportTypeInfo("theBooleanArrayTypeInfo")
public final class BooleanArray {
/**
* Creates a new array of the specified [size], with all elements initialized to `false`.
*
* @throws RuntimeException if the specified [size] is negative.
*/
// Constructors are handled with the compiler magic.
public constructor(@Suppress("UNUSED_PARAMETER") size: Int) {}
@@ -476,6 +531,8 @@ public final class BooleanArray {
*
* The function [init] is called for each array element sequentially starting from the first one.
* It should return the value for an array element given its index.
*
* @throws RuntimeException if the specified [size] is negative.
*/
@Suppress("WRONG_MODIFIER_TARGET")
public inline constructor(size: Int, init: (Int) -> Boolean): this(size) {