Another possible optional inference improvement


I just wrote a code like this:

val chosenProfile = /* some expression that can be null, i.e. QQQ? */

    if (chosenProfile?.likesUser == true) {
    ....., extra)

The compiler says “Error:(316, 32) Type mismatch: inferred type is QQQ? but QQQ was expected”.

I think it can be inferred that if the program reaches here, the type is QQQ.


this was with kt 1.0.4


This improvement is already implemented in 1.1, if I’m not mistaken.