New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve error reporting: Missing "else" branch for if / elif expression #1157
Comments
I think I already know why this is reported in wrong order. I think I But first things first. I will add tests for this to my other pr. Hopefully
|
With Steffen's PR It now yields this error: I think the advice portion is accurate and relevant. What do you think?
|
It's definitely a big improvement :-) My only question (and this is across all the if / else issues) is what is a "then" branch? Surely it should be the "if" branch as there are several occurrence of "then" within an if / else expression. |
@forki Just noticed that this only works for simple values. If there's a function in between, it fails e.g. let foo x = x + 1
let x = if true then (foo 5) gives the error:
If I remove the let x = if true then 5 Then it works properly:
Both errors have the same error code which suggests that the compiler understands it's the same error - it's just the it's getting the text from a different place or something? |
What
Related to #1104, but not the same. The following code leads to an especially cryptic error message from the compiler:
As if is an expression in F#, you need to provide an
else
branch as well. The error message shown below is related to theelif
branch above (but not theif
branch): -Why
What's especially confusing about this error (in addition to the points put forward in #1104) is that the error suggests that the type being returned from this branch is a unit when in fact it is a string. Even worse, if you comment out the elif branch so that you just have the if branch, the types in the error message become inverted!
How
As per #1104.
The text was updated successfully, but these errors were encountered: