Fix array init and add listOf(). (#109)
This commit is contained in:
+1
@@ -36,6 +36,7 @@ class KonanBuiltIns: KotlinBuiltIns {
|
||||
object KonanPlatform : TargetPlatform("Konan") {
|
||||
override val defaultImports: List<ImportPath> = Default.defaultImports + listOf(
|
||||
ImportPath("kotlin.*"),
|
||||
ImportPath("kotlin.collections.*"),
|
||||
ImportPath("kotlin.io.*"),
|
||||
ImportPath("konan.*")
|
||||
)
|
||||
|
||||
@@ -478,7 +478,7 @@ task array_list1(type: RunKonanTest) {
|
||||
}
|
||||
|
||||
task listof0(type: RunKonanTest) {
|
||||
goldValue = "abc\n"
|
||||
goldValue = "abc\n[a, b, c, d]\n[n, s, a]\n"
|
||||
source = "runtime/collections/listof0.kt"
|
||||
}
|
||||
|
||||
|
||||
@@ -2,4 +2,9 @@ fun main(args : Array<String>) {
|
||||
val list = arrayListOf("a", "b", "c")
|
||||
for (element in list) print(element)
|
||||
println()
|
||||
list.add("d")
|
||||
println(list.toString())
|
||||
|
||||
val list2 = listOf("n", "s", "a")
|
||||
println(list2.toString())
|
||||
}
|
||||
@@ -10,8 +10,7 @@ public final class String : Comparable<String>, CharSequence {
|
||||
@SymbolName("Kotlin_String_hashCode")
|
||||
external public override fun hashCode(): Int
|
||||
|
||||
// TODO: make it Any?
|
||||
public operator fun plus(other: Any): String {
|
||||
public operator fun plus(other: Any?): String {
|
||||
return plusImpl(other.toString())
|
||||
}
|
||||
|
||||
|
||||
@@ -149,7 +149,6 @@ class ArrayList<E> private constructor(
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
//TODO: rethink instance checks, shall it be other is List<*>?
|
||||
return other === this ||
|
||||
(other is List<*>) && contentEquals(other)
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ package kotlin.collections
|
||||
* either throwing exception or returning some kind of implementation-specific default value.
|
||||
*/
|
||||
fun <E> arrayOfLateInitElements(size: Int): Array<E> {
|
||||
// TODO: maybe use an empty array, fix array creation.
|
||||
// TODO: maybe use an empty array.
|
||||
// return (if (size == 0) emptyArray else Array<Any>(size)) as Array<E>
|
||||
return Array<Any>(size) as Array<E>
|
||||
return Array<E>(size)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -17,7 +17,7 @@ fun <E> arrayOfLateInitElements(size: Int): Array<E> {
|
||||
* either throwing exception or returning some kind of implementation-specific default value.
|
||||
*/
|
||||
fun <E> Array<E>.copyOfLateInitElements(newSize: Int): Array<E> {
|
||||
val result = Array<Any>(newSize) as Array<E>
|
||||
val result = Array<E>(newSize)
|
||||
this.copyRangeTo(result, 0, if (newSize > this.size) this.size else newSize, 0)
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -23,9 +23,17 @@ public interface MutableIterable<out T> : Iterable<T> {
|
||||
override fun iterator(): MutableIterator<T>
|
||||
}
|
||||
|
||||
fun <E> Array<E>.asList(): List<E> {
|
||||
// TODO: consider making lighter list over an array.
|
||||
val result = ArrayList<E>(this.size)
|
||||
for (e in this) {
|
||||
result.add(e)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
public fun <T> arrayListOf(vararg args: T): MutableList<T> {
|
||||
// TODO: fix me!
|
||||
val result = ArrayList<Any>(args.size) as ArrayList<T>
|
||||
val result = ArrayList<T>(args.size)
|
||||
for (arg in args) {
|
||||
result.add(arg)
|
||||
}
|
||||
@@ -33,10 +41,7 @@ public fun <T> arrayListOf(vararg args: T): MutableList<T> {
|
||||
}
|
||||
|
||||
/*
|
||||
* FIXME: Suggested code from @olonho is following
|
||||
*
|
||||
* public fun <T> listOf(element: T): List<T> = arrayListOf(element)
|
||||
*
|
||||
* but in Big Kotlin this function is following: (see libraries/stdlib/src/kotlin/collections/Collections.kt)
|
||||
* TODO: in Big Kotlin this function is following: (see libraries/stdlib/src/kotlin/collections/Collections.kt)
|
||||
* public fun <T> listOf(vararg elements: T): List<T> = if (elements.size > 0) elements.asList() else emptyList()
|
||||
*/
|
||||
public fun <T> listOf(vararg args: T): List<T> = args.asList()
|
||||
Reference in New Issue
Block a user