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:
Dmitry Petrov
2015-12-30 16:02:48 +03:00
parent ffd1bcf72f
commit b736880787
12 changed files with 188 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
// NB '!!' uses Intrinsics.throwNpe()
inline fun exit(): Nothing = null!!
fun box(): String {
val a: String
try {
a = "OK"
}
catch (e: Exception) {
exit()
// ATHROW
}
return a
}
// 1 ATHROW

View File

@@ -0,0 +1,16 @@
inline fun exit(): Nothing =
throw RuntimeException() // ATHROW
fun box(): String {
val a: String
try {
a = "OK"
}
catch (e: Exception) {
exit() // ATHROW inlined
// no ATHROW (removed as dead code)
}
return a
}
// 2 ATHROW

View File

@@ -0,0 +1,17 @@
inline fun exit(): Nothing = null!!
inline fun exita(): Nothing = exit() // ATHROW
inline fun exitb(): Nothing = exita() // ATHROW
inline fun exitc(): Nothing = exitb() // ATHROW
fun box(): String {
val a: String
try {
a = "OK"
}
catch (e: Exception) {
exitc() // ATHROW
}
return a
}
// 4 ATHROW