Check for index-out-of-bound in elementAt function (KT-30051)

This commit is contained in:
Abduqodiri Qurbonzoda
2019-03-07 22:10:29 +03:00
parent 584137121b
commit ba61695a45
16 changed files with 496 additions and 60 deletions
@@ -284,6 +284,22 @@ object Elements : TemplateGroupBase() {
inlineOnly()
body { "return get(index)" }
}
specialFor(CharSequences, ArraysOfObjects, ArraysOfPrimitives, ArraysOfUnsigned) {
on(Platform.Common) {
inline(Inline.No)
}
on(Platform.JS) {
inline(Inline.No)
val size = if (f == CharSequences) "length" else "size"
body {
"""
return elementAtOrElse(index) { throw IndexOutOfBoundsException("index: $index, $size: $$size}") }
"""
}
}
}
}
val f_elementAtOrElse = fn("elementAtOrElse(index: Int, defaultValue: (Int) -> T)") {