Stream: t-compiler/wg-rls-2.0

Topic: Semicolons after `return` spoils type inference


Kirill Bulatov (Aug 27 2019 at 13:54, on Zulip):

I've just noticed that the type is inferred incorrectly when a semicolon added to the return keyword.

This works fine with the PR that fixes Never inference

let i = if true {
        2.0
    } else {
        return
    };

inferring f64 for i but if you add any number of semicolons after return, the type for i gets inferred as ().

Any code pointers I can look at to fix the issue?

Florian Diebold (Aug 27 2019 at 14:58, on Zulip):

rustc basically notices that the code path diverges and makes its type !. So we'd need to do something similar

Florian Diebold (Aug 27 2019 at 15:16, on Zulip):

so that's a bit involved and requires some refactoring since we need to keep track of whether the code path diverges

Kirill Bulatov (Aug 27 2019 at 15:59, on Zulip):

Nice, looks like the next thing to work on after Never coercion is merged, thank you.

Last update: Nov 19 2019 at 17:35UTC