Kotlin RxJava Nullable Bug : <p>I've run into an issue in my Android app using Kotlin and RxJava. It's presented below.</p>

<pre><code>import rx.Observable

data class TestUser(val name: String)

fun getTestUser(): Observable&lt;TestUser&gt; {
    return Observable.just(TestUser("Brian")).flatMap { getUser() } // this compiles
}

fun getTestUser2(): Observable&lt;TestUser&gt; {
    val observable = Observable.just(TestUser("Brian")).flatMap { getUser() }
    return observable // this does not compile
}

fun getUser(): Observable&lt;TestUser?&gt; {
    return Observable.just(null)
}
</code></pre>

<p>In <code>getTestUser2</code>, the compiler infers the final return type as <code>Observable&lt;TestUser?&gt;</code> and doesn't compile. However in <code>getTestUser</code> the code does compile, and when it's run, any subscriber to that observable may be in for a surprise when the <code>TestUser</code> comes back <code>null</code>.</p>

<p>I'm guessing it's something to do with going back and forth between Kotlin and Java. But, the fact that the compiler <em>can</em> see the difference in <code>getTestUser2</code> makes me think this could be fixable.</p>

<p>Edit</p>

<p>This is on Kotlin 1.0, the final version released just yesterday (Feb 15, 2016).</p>
