Fix issue getting the size property from Collection bounded type

parameters, when lowering for-loops over Collection.indices.
This commit is contained in:
Mark Punzalan
2019-11-06 13:51:51 -08:00
committed by max-kammerer
parent 30679ebfaf
commit 21178a4f1a
13 changed files with 131 additions and 3 deletions
@@ -0,0 +1,17 @@
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
fun <T: CharSequence> test(s: T): Int {
var result = 0
for (i in s.indices) {
result = result * 10 + (i + 1)
}
return result
}
fun box(): String {
val test = test("abcd")
if (test != 1234) return "Fail: $test"
return "OK"
}
@@ -0,0 +1,20 @@
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
import kotlin.test.assertEquals
fun <T : Collection<*>> sumIndices(c: T): Int {
var sum = 0
for (i in c.indices) {
sum += i
}
return sum
}
fun box(): String {
val list = listOf(0, 0, 0, 0)
val sum = sumIndices(list)
assertEquals(6, sum)
return "OK"
}