https://kotlinlang.org logo
Title
b

blyn

10/29/2018, 8:49 PM
AS is yelling at me after Kotlin 1.3, i’m assuming due to the new contracts:
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

orangy

10/29/2018, 8:53 PM
Did you update the IDE plugin? I pasted this into IJ (don’t have AS handy) and there are no issues.
👍 1
s

skennedy

10/29/2018, 8:57 PM
this exact issue works for me in AS 3.3 with the latest kotlin plugin
b

blyn

10/29/2018, 8:57 PM
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

mattinger

10/30/2018, 2:52 AM
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:
@kotlin.internal.InlineOnly
public inline fun CharSequence?.isNullOrEmpty(): Boolean {
    contract {
        returns(false) implies (this@isNullOrEmpty != null)
    }

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

marstran

10/30/2018, 8:47 AM