Fix casts of Unit value to other types
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
fun println(s: String) {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
println(":Hi!") as Any
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fun println(s: String) {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = println(":Hi!") as Any
|
||||
if (x != Unit) return "Fail: $x"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fun println(s: String) {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = println(":Hi!") as? Any
|
||||
if (x != Unit) return "Fail: $x"
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
fun foo() {}
|
||||
|
||||
fun box(): String {
|
||||
try {
|
||||
foo() as Int?
|
||||
}
|
||||
catch (e: ClassCastException) {
|
||||
return "OK"
|
||||
}
|
||||
catch (e: Throwable) {
|
||||
return "Fail: ClassCastException should have been thrown, but was instead ${e.javaClass.getName()}: ${e.getMessage()}"
|
||||
}
|
||||
|
||||
return "Fail: no exception was thrown"
|
||||
}
|
||||
Reference in New Issue
Block a user