mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 08:31:26 +00:00
Support lateinit local vars in redundant null check elimination
Lateinit local vars are guaranteed to be non-null after store. So we mark such stores as storing non-null value (could be useful for some other constructs, too), and optimize null checks accordingly.
This commit is contained in:
19
compiler/testData/codegen/bytecodeText/nullCheckOptimization/localLateinit/checkedOnce.kt
vendored
Normal file
19
compiler/testData/codegen/bytecodeText/nullCheckOptimization/localLateinit/checkedOnce.kt
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
// LANGUAGE_VERSION: 1.2
|
||||
|
||||
fun almostAlwaysTrue() = true
|
||||
|
||||
fun test() {
|
||||
lateinit var z: String
|
||||
run {
|
||||
if (almostAlwaysTrue()) {
|
||||
z = ""
|
||||
}
|
||||
}
|
||||
println(z)
|
||||
println(z)
|
||||
println(z)
|
||||
}
|
||||
|
||||
// 0 IFNULL
|
||||
// 1 IFNONNULL
|
||||
// 1 throwUninitializedPropertyAccessException
|
||||
Reference in New Issue
Block a user