Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin 1.3.11 has broken null-safety?

Tags:

kotlin

fun handle() : String {
    null?.let { return "Ololo"}
}

val result = handle()
result.trim() // kotlin.TypeCastException: null cannot be cast to non-null type kotlin.CharSequence

Any ideas why null-safe Kotlin function return null?

like image 310
Nickolay Savchenko Avatar asked Jan 06 '19 19:01

Nickolay Savchenko


1 Answers

It's a bug caused by introducing contracts for the standard functions let, run, apply, also in Kotlin 1.3.

The fix is targeted to the version 1.3.20. See KT-28061 for details.

like image 122
Ilya Avatar answered Oct 03 '22 16:10

Ilya