-
Notifications
You must be signed in to change notification settings - Fork 262
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
Do not refer to an implicit assignment in error messages on return stmts #3130
Do not refer to an implicit assignment in error messages on return stmts #3130
Conversation
…atements Previously, a type error in a method `return` statement refers to an assignment, because the Resolver treats a return as an implicit update to the named return variable. This patch checks whether an assignment is updating a formal outparameter and produces a more specific error message if so.
Note that a consequence of this patch is that direct assignments to the named return variable talk about the return type of the method, rather than the assignment.
Personally, I don't think this is confusing, but I don't know if folks have strong opinions about this; given that during treewalking, at the point of reporting the type error we've forgotten whether the statement is an UpdateStmt or a ReturnStmt, I'm not sure there's an ideal solution here that isn't super-invasive... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds great ! I have an idea to mitigate the effect and use this new error message more precisely. See my comments.
I had a bit of time this morning, and since #3125 was derived from an essentially-not-an-issue issue that I filed, made sense that I should take a swing at resolving it!
Previously, a type error in a method
return
statement refers to an assignment, because the Resolver treats a return as an implicit update to the named return variable. This patch checks whether an assignment is updating a formal outparameter and produces a more specific error message if so.Given the following Dafny program,
The errors produced are:
This also updates existing unit tests that expected the old error message - I think I've caught them all but CI will let me know if I'm wrong :-)
Fixes #3125
By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.