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:
committed by
SvyatoslavScherbina
parent
9bf0380048
commit
65444ec690
@@ -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
|
||||
Reference in New Issue
Block a user