Suppress UNCHECKED_CAST instead of CAST_NEVER_SUCCEEDS in several places

This is related to KT-6611 being fixed recently. Note that not all cases of
incorrect "cast never succeeds" were fixed
This commit is contained in:
Alexander Udalov
2016-07-12 21:32:35 +03:00
parent 13b0fda3c2
commit 8f33830f29
10 changed files with 15 additions and 17 deletions
@@ -159,7 +159,7 @@ fun filtering(): List<GenericFunction> {
val list = ArrayList<T>(n)
for (item in this) {
if (count++ == n)
break;
break
list.add(item)
}
return list
@@ -292,7 +292,7 @@ fun filtering(): List<GenericFunction> {
val list = ArrayList<T>()
for (item in this) {
if (!predicate(item))
break;
break
list.add(item)
}
return list
@@ -13,14 +13,14 @@ fun guards(): List<GenericFunction> {
typeParam("T : Any")
toNullableT = true
returns("SELF")
body { f ->
body {
"""
for (element in this) {
if (element == null) {
throw IllegalArgumentException("null element found in $THIS.")
}
}
@Suppress("${if (f == InvariantArraysOfObjects) "CAST_NEVER_SUCCEEDS" else "UNCHECKED_CAST"}")
@Suppress("UNCHECKED_CAST")
return this as SELF
"""
}
@@ -32,4 +32,4 @@ fun guards(): List<GenericFunction> {
}
return templates
}
}
@@ -102,7 +102,7 @@ fun ordering(): List<GenericFunction> {
"""
if (this is Collection) {
if (size <= 1) return this.toList()
@Suppress("CAST_NEVER_SUCCEEDS")
@Suppress("UNCHECKED_CAST")
return (toTypedArray<Comparable<T>>() as Array<T>).apply { sort() }.asList()
}
return toMutableList().apply { sort() }
@@ -232,7 +232,7 @@ fun ordering(): List<GenericFunction> {
"""
if (this is Collection) {
if (size <= 1) return this.toList()
@Suppress("CAST_NEVER_SUCCEEDS")
@Suppress("UNCHECKED_CAST")
return (toTypedArray<Any?>() as Array<T>).apply { sortWith(comparator) }.asList()
}
return toMutableList().apply { sortWith(comparator) }