KT-9377 Support is-checks for read-only collections

Generate better code for 'as?' with mutable collection types:
use CHECKCAST, do not introduce special intrinsics for safe-as.
This commit is contained in:
Dmitry Petrov
2015-10-02 11:56:56 +03:00
parent e033d093d4
commit 06d9ff6a71
6 changed files with 46 additions and 125 deletions
@@ -0,0 +1,13 @@
// For mutable collections and related types (e.g., MutableList, MutableListIterator)
// 'as?' should be generated as a single 'safeAs...' intrinsic call
// without instanceof or 'is...'.
fun test() {
val x: Any = arrayListOf("abc", "def")
x as? MutableList<*>
}
// 0 INSTANCEOF
// 1 INVOKESTATIC kotlin/jvm/internal/TypeIntrinsics\.isMutableList
// 0 INVOKESTATIC kotlin/jvm/internal/TypeIntrinsics\.asMutableList
// 1 CHECKCAST java/util/List