-
Notifications
You must be signed in to change notification settings - Fork 260
[BUG] Last use of member function cannot be inout this #999
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
Comments
Thanks! I think this is resolved by 7041994, by making the error message better. It's actually intentional that this is an error. Briefly, the reason is that if a definite last use of a local object modifies that object, then the code is not looking at the object again (because by definition it's a last use) and therefore trying to implicitly discard the new value. For a complete discussion, please see Design note: Explicit discard. However, you are correct that the error message above is terrible. Fortunately, I just fixed that in commit 7041994... now for the latter program above, the diagnostic is much better, it starts with this:
Followed by semi-useful information (showing MSVC output here):
|
However, based on this feedback I think changing the first error message as follows would be clearer about the actual problem, and advise how to fix it:
Thanks! |
I'm not convinced about the semantics of explicit discard in this situation. I'm thinking about RAII-style types, e.g.: raii: type = {
operator=: (out this) = {
f = nullptr;
// Pretend this is: fopen(...);
}
operator=: (move this) = {
// Pretend this is: fclose(...);
}
write: (inout this, something: int) = {
// Pretend this is: fwrite(...);
}
f: *FILE;
}
main: () -> int = {
{
file: raii = ();
file.write(55);
}
return 0;
} I'd find it awkward to have to write |
OK, reopened. See also my comment on #1002 which also came down to "this is about guard objects I think"... |
Thanks! See #1030, this should now be fixed in the above commit. Both code examples above will now work. |
Brief update re Neil's While this specific example isn't quite a "guard" in the usual sense, I want to try out the path of |
I think this is similar to this bug #888 because i believe it's to do with the implicit move.
If the second to last member function is (inout this) the code runs as expected. But if you comment out or remove the "x.print();" making "x.inc();" that is an (inout this) the last use of x. then it falls apart.
The text was updated successfully, but these errors were encountered: