Make mutating the same value that is returned, in a defer, an error #1324
Tetralux
started this conversation in
Ideas/Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Spoiler:
result == 1.I think this is should be a compile error.
I'm struggling to think of even a single case where this isn't a bug: Mutating the same value that is returned, in a defer statement.
If you internalise that defers run after the return statement, then it might be easier to resolve this in your mind - but I think it's a bit error prone, as it is easy to fall into the trap here. And, more importantly, if you do fall into the trap, it's likely a bugger to debug!
You could also extend this to procedure calls in defers, as well.
Perhaps this can also be an error.
If, when checking procedure bodies, the 'mutability' of parameters is flagged, then detection for this within
fis trivial:gwrites through its pointer parameterptr&xis passed to it in the defer; andxis returned fromf.Beta Was this translation helpful? Give feedback.
All reactions