AS is yelling at me after Kotlin 1.3, i’m assuming...
# android
b
AS is yelling at me after Kotlin 1.3, i’m assuming due to the new contracts:
Copy code
private fun foo(value: String?) {
        var myString: String = ""

        if (!value.isNullOrEmpty()) {
            myString = value
        }
    }
IDE complains that there’s a type mismatch between
myString
and
value
, but the compile builds no problem (and warns if i explicitly
!!
). Is there anyway around this?
o
Did you update the IDE plugin? I pasted this into IJ (don’t have AS handy) and there are no issues.
👍 1
s
this exact issue works for me in AS 3.3 with the latest kotlin plugin
b
Weird, i’m getting the error on both
3.2.1
and
3.3.0-beta01
Sounds like it’s my environment somehow though, thanks for confirming.
Oh and kotlin plugin
1.3.0
m
Is the compiler smart enough to deal with .isNullOrEmpty and know that it's no longer nullable? I know it would do this if you put != null, but not sure with the function.
i suppose in 1.3 it might given the implementation:
Copy code
@kotlin.internal.InlineOnly
public inline fun CharSequence?.isNullOrEmpty(): Boolean {
    contract {
        returns(false) implies (this@isNullOrEmpty != null)
    }

    return this == null || this.length == 0
}
m