-
-
Notifications
You must be signed in to change notification settings - Fork 419
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
Confusing error message when method only includes variable declarations #2828
Comments
I think this is more generally a problem with the error message. At the very least maybe we could have a hint that says something about "destructive read" to give people a place to look? I don't necessarily think we need a specific error message for this situation (where the code indicates that the result of an initial destructive read should be returned by the function). I think the second error is also confusing (or even inaccurate) and should probably not appear. |
I'd like to tackle this issue. |
@adri326 have at it! |
This addresses #2828 Declaring a variable at the end of a function which expects a return value or having generally a variable declaration where the compiler expects to use the return value caused in most cases an error stating that the variable is undefined but its value is used: ``` actor Main new create(env:Env) => confusing_error_msg() fun confusing_error_msg(): String => var s = "A string." ``` This bit of code triggers the following error on 0.33.1: ``` Error: main.pony:26:9: the left side is undefined but its value is used var s = "A string." ^ Error: main.pony:26:11: left side must be something that can be assigned to var s = "A string." ^ ``` The presence of the second error was also considered to be erroneous. This patch discriminates in the `is_lvalue` function from `pass/refer.c` cases where the left-hand side of the assignment is not an `lvalue` and cases where it triggers an error. This way, the compiler can tell between the left side not being something that can be assigned to or it having triggered an error. Additionally, an *Info* message is triggered when the left side's old value is needed in a declaration. This is what the error message now looks like: ``` Error: main.pony:6:9: the left side is undefined but its value is used var s = "A string." ^ Info: main.pony:6:5: the previous value of 's' is used because you are trying to use the resulting value of this var declaration var s = "A string." ^ ```
ponyc version:
source:
compiler output:
Furthermore, changing the return type of
confusing_error_msg
toNone
results in a successful build, without any error output mentioning unused variables. I remember receiving errors regarding unused declarations previously, and am unsure if they are still a compilation error.The text was updated successfully, but these errors were encountered: