Flow reports implicitly returned undefined even when not possible
- Dominant language
- Rust
- Stars
- 22.3k
- Forks
- 1.9k
- PR merge metrics
- No merged PRs in 30d
Description
I keep running into more complex version of [this example code](https://flowtype.org/try/#0PQKgBAAgZgNg9gdzCYAoVBjOA7AzgFzAFMAPAWwAcYwBeMACgEtsKBXfALm1bICMiATgEouPfgNoA+MAG9UYMAgAWjGEQb4BrIkNnyFYXAkb4MShszb5dcgwYwBDXOoAMHfXYUCi+VgOxgluweBgAmRFAOrDCcIXbevv5gLiEAvvrpqUA) fairly often:
```js
/* @flow */
const exmpl = (input:number):number => {
while (true) {
switch (input) {
case 0:
return input
default:
return 0
}
}
}
```
Which flow fails to type check with a following error:
```
3: const exmpl = (input:number):number => {
^ number. This type is incompatible with an implicitly-returned undefined.
```
Most likely flow is failing to infer that `while` block will ever be executed. I am not sure how difficult would it be make flow type check this code, but either way it would really help if flow provided a hint on why it assumes implicitly returned `undefined` something, telling user that while block may never run would greatly improve usability.
Contributor guide
Assessment
This issue has not been assessed yet.