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
@@ -4,12 +4,9 @@ import java.util.HashSet
fun iarray(vararg a : Int) = a // BUG
fun IntArray.lastIndex() = size - 1
fun IntArray.lastIndex() = size() - 1
fun box() : String {
// Problematic code does not compile
// val vals = iarray(789, 678, 567, 456, 345, 234, 123, 012)
val vals = iarray(789, 678, 567, 456, 345, 234, 123, 12)
val diffs = HashSet<Int>()
for (i in vals.indices)
@@ -3,13 +3,13 @@ fun foo(a: Int, vararg b: Int, f: (IntArray) -> String): String {
}
fun box(): String {
val test1 = foo(1) {a -> "" + a.size}
val test1 = foo(1) {a -> "" + a.size()}
if (test1 != "test1 0") return test1
val test2 = foo(2, 2) {a -> "" + a.size}
val test2 = foo(2, 2) {a -> "" + a.size()}
if (test2 != "test2 1") return test2
val test3 = foo(3, 2, 3) {a -> "" + a.size}
val test3 = foo(3, 2, 3) {a -> "" + a.size()}
if (test3 != "test3 2") return test3
return "OK"