mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 15:53:19 +00:00
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:
16
compiler/testData/codegen/bytecodeText/inline/inlineReturnsNothing1.kt
vendored
Normal file
16
compiler/testData/codegen/bytecodeText/inline/inlineReturnsNothing1.kt
vendored
Normal 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
|
||||
16
compiler/testData/codegen/bytecodeText/inline/inlineReturnsNothing2.kt
vendored
Normal file
16
compiler/testData/codegen/bytecodeText/inline/inlineReturnsNothing2.kt
vendored
Normal 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
|
||||
17
compiler/testData/codegen/bytecodeText/inline/inlineReturnsNothing3.kt
vendored
Normal file
17
compiler/testData/codegen/bytecodeText/inline/inlineReturnsNothing3.kt
vendored
Normal 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
|
||||
Reference in New Issue
Block a user