KT-6646, KT-10482:
when a method (or a property getter) returns Nothing, emit ACONST_NULL ATHROW after a call so that class files verifier knows that this is an exit point in a method. Note that if an inline method returning Nothing throws an exception explicitly (or via a chain of inline methods), this code will be deleted by DCE.
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
var flag = true
|
||||
|
||||
fun exit(): Nothing = null!!
|
||||
|
||||
fun box(): String {
|
||||
val a: String
|
||||
if (flag) {
|
||||
a = "OK"
|
||||
}
|
||||
else {
|
||||
exit()
|
||||
}
|
||||
return a
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
inline fun exit(): Nothing = null!!
|
||||
|
||||
fun box(): String {
|
||||
val a: String
|
||||
try {
|
||||
a = "OK"
|
||||
}
|
||||
catch (e: Exception) {
|
||||
exit()
|
||||
}
|
||||
return a
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
var flag = true
|
||||
|
||||
object Test {
|
||||
val magic: Nothing get() = null!!
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val a: String
|
||||
if (flag) {
|
||||
a = "OK"
|
||||
}
|
||||
else {
|
||||
Test.magic
|
||||
}
|
||||
return a
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fun exit(): Nothing = null!!
|
||||
|
||||
fun box(): String {
|
||||
val a: String
|
||||
try {
|
||||
a = "OK"
|
||||
}
|
||||
catch (e: Exception) {
|
||||
exit()
|
||||
}
|
||||
return a
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
fun exit(): Nothing = null!!
|
||||
|
||||
var x = 0
|
||||
|
||||
fun box(): String {
|
||||
val a: String
|
||||
when (x) {
|
||||
0 -> a = "OK"
|
||||
1 -> a = "???"
|
||||
2 -> exit()
|
||||
else -> exit()
|
||||
}
|
||||
return a
|
||||
}
|
||||
Reference in New Issue
Block a user