Add missing unsigned array constructors (from size)

#KT-25961 Fixed
This commit is contained in:
Ilya Gorbunov
2018-07-04 20:07:11 +03:00
parent 282cf73aff
commit f9479d12f9
7 changed files with 94 additions and 4 deletions
+7 -4
View File
@@ -292,6 +292,9 @@ class UnsignedArrayGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIn
out.println("internal constructor(private val storage: $storageArrayType) : Collection<$elementType> {")
out.println(
"""
/** Creates a new array of the specified [size], with all elements initialized to zero. */
public constructor(size: Int) : this($storageArrayType(size))
/** Returns the array element at the given [index]. This method can be called using the index operator. */
public operator fun get(index: Int): $elementType = storage[index].to$elementType()
@@ -322,10 +325,10 @@ class UnsignedArrayGenerator(val type: UnsignedType, out: PrintWriter) : BuiltIn
out.println("}")
// TODO: Make inline constructor, like in ByteArray
out.println()
out.println("@SinceKotlin(\"1.3\")")
out.println("@ExperimentalUnsignedTypes")
out.println("""public inline fun $arrayType(size: Int, init: (Int) -> $elementType): $arrayType {
out.println("""
@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
public inline fun $arrayType(size: Int, init: (Int) -> $elementType): $arrayType {
return $arrayType($storageArrayType(size) { index -> init(index).to$storageElementType() })
}