Please look at this code:
fun localVarNullSafety1(){
var number: Double? = 3.0
val sum = 2.0 + number // does not compile (Type mismatch: inferred type is Double? but Double was expected)
}
fun localVarNullSafety1(){
var number: Double? = null
number = 3.0
val sum = 2.0 + number // compiles fine
}
I think that the above code consists of semantically identical functions - local variables don't go outside the scope, and they are local to the executing thread. In my opinion there is no reason for the first function not to compile.
I think that Kotlin's smart cast should take variable initialization into account.
Do I miss something obvious?