Could anyone explain the result of following code snippet? Why the first function call returns kotlin.Unit?
kotlin version 1.5.21, java11
fun <T> testMethod(data: String?): T? = data?.let { return null }
println(testMethod<String>(null)) // --> kotlin.Unit
fun <T> testMethod2(data: String?): T? = data?.let { null }
println(testMethod2<String>(null)) // --> null
Why the result is different in kotlin 1.4.30 - https://pl.kotl.in/uFZDE3O9e?
It was a compiler issue and already reported here - https://youtrack.jetbrains.com/issue/KT-47527, fixed in 1.6.0-dev-970.
Ref: https://github.com/jetbrains/kotlin/commit/ae608ea67fc589c4472657dc0317e97cb67dd158
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With