I wrote this code:
var test: String? = null
get() {
field?.also {
return "has value"
}
}
It reaches return
only when the field is non-null. Otherwise the body just completes. Nevertheless, this compiles fine and returns null
if field is null.
If I change to this:
var test: String? = null
get() {
if (field != null)
return "has value"
}
now the compiler complains that the block body needs a return statement.
Is this some undocumented feature or a bug?