Make Array.size() a function instead of a property

Also add a deprecated extension property to help migration. This is done to
unify getting size of arrays and collections
This commit is contained in:
Alexander Udalov
2014-11-14 18:02:04 +03:00
parent bc238d5f4c
commit 128c938965
67 changed files with 677 additions and 625 deletions
@@ -6,55 +6,55 @@ fun foo(a: Any): Int {
a.set(0, 1)
a.iterator()
a.indices
return a.size
return a.size()
}
if (a is ShortArray) {
a.get(0)
a.set(0, 1)
a.iterator()
a.indices
return a.size
return a.size()
}
if (a is ByteArray) {
a.get(0)
a.set(0, 1)
a.iterator()
a.indices
return a.size
return a.size()
}
if (a is FloatArray) {
a.get(0)
a.set(0, 1.toFloat())
a.iterator()
a.indices
return a.size
return a.size()
}
if (a is DoubleArray) {
a.get(0)
a.set(0, 1.0)
a.iterator()
a.indices
return a.size
return a.size()
}
if (a is BooleanArray) {
a.get(0)
a.set(0, false)
a.iterator()
a.indices
return a.size
return a.size()
}
if (a is CharArray) {
a.get(0)
a.set(0, 'a')
a.iterator()
a.indices
return a.size
return a.size()
}
if (a is Array<*>) {
if (a.size > 0) a.get(0)
if (a.size() > 0) a.get(0)
a.iterator()
a.indices
return a.size
return a.size()
}
return 0
@@ -22,11 +22,8 @@ fun box() : String {
catch (e : ArrayIndexOutOfBoundsException) {
// No more tests to process
}
System.out?.println(n)
return if(n == 2) "OK" else "fail"
}
fun thirdElementIsThree(a : IntArray) =
// Problematic code does not compile
// a.size >= 3 & a[2] == 3
a.size >= 3 && a[2] == 3
a.size() >= 3 && a[2] == 3
@@ -1,3 +1,3 @@
val <T> Array<T>.length : Int get() = this.size
val <T> Array<T>.length : Int get() = this.size()
fun box() = if(Array(10, {1}).length == 10) "OK" else "fail"