backend: improve type operators support:

* add initial support for casts with generics;
* optimize out the casts to subtypes

Also add tests unchecked_cast{1,2}, the latter is disabled.
This commit is contained in:
Svyatoslav Scherbina
2017-01-20 11:20:32 +07:00
committed by SvyatoslavScherbina
parent 9bf0380048
commit 65444ec690
7 changed files with 94 additions and 33 deletions
@@ -0,0 +1,16 @@
fun main(args: Array<String>) {
foo<String>("17")
bar<String>("17")
foo<String>(42)
bar<String>(42)
}
fun <T> foo(x: Any?) {
val y = x as T
println(y.toString())
}
fun <T> bar(x: Any?) {
val y = x as? T
println(y.toString())
}
@@ -0,0 +1,10 @@
fun main(args: Array<String>) {
try {
val x = cast<String>(Any())
println(x.length)
} catch (e: Throwable) {
println("Ok")
}
}
fun <T> cast(x: Any?) = x as T