-
Notifications
You must be signed in to change notification settings - Fork 257
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
Unhelpful error message about reads clause #5262
Labels
kind: enhancement
Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny
part: documentation
Dafny's reference manual, tutorial, and other materials
Comments
MikaelMayer
added
kind: bug
Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label
part: documentation
Dafny's reference manual, tutorial, and other materials
kind: enhancement
Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny
and removed
kind: bug
Crashes, unsoundness, incorrect output, etc. If possible, add a `part:` label
labels
Mar 27, 2024
MikaelMayer
added a commit
that referenced
this issue
Mar 29, 2024
This PR enhances the error message, giving more context. Fixes #5262 For example, in the context of a method where `x` is a field, x := 5; f := () => if 5 / x == 1 then 2 else 3; ^ Error here Instead of saying git-issue-405.dfy(19,22): Error: insufficient reads clause to read field the new message is more helpful: git-issue-405.dfy(19,22): Error: insufficient reads clause to read field; Consider extracting this.x to a local variable, or adding 'reads this' in the enclosing lambda specification for resolution The first part of this message is added only for lambda expressions, the second part is always present for scope tolerating a reads clause. For scopes such as functions or methods, where the reads clause can sometimes be more fine-grained, the hint `or 'reads this`x'` is added for discoverability. For scopes without a possible resolution, the following error message is now emitted: Error: insufficient reads clause to read field; Mutable fields cannot be accessed within certain scopes, such as default values or the right-hand side of constants For a function by method, the scope is the function and not the method body. <small>By submitting this pull request, I confirm that my contribution is made under the terms of the [MIT license](https://github.com/dafny-lang/dafny/blob/master/LICENSE.txt).</small>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
kind: enhancement
Enhancements, feature requests, etc. These are NOT bugs, but ways we can improve Dafny
part: documentation
Dafny's reference manual, tutorial, and other materials
Dafny version
latest-nightly
Code to produce this issue
Command to run and resulting output
What happened?
I did not get it why it could not read the array "entries" since it's in a method.
It turns out, "entries" is a shortcut for "this.entries", which means that this expression requires "reads this".
I think I would have immediately spotted it if, instead of the error message:
I would have had the following error message, at least because "this" is implicit.
What type of operating system are you experiencing the problem on?
Windows
The text was updated successfully, but these errors were encountered: