-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Deconstructions do not detect self assignments #16870
Comments
I imagine that this is because the tuple literal expression and the deconstruction assignment are considered two effectively unrelated things. If #16869 were considered and the "deconstruction" instead converted into two simple assignments then the warning would make sense. |
@HaloFour I think that's just an implementation detail, in effect, you are self-assigning a variable anyways. |
I agree, that is the net result. But the compiler might see it more like you're calling a constructor with Either way, I agree that this is probably a useful warning. |
@HaloFour I think the actual mechanism from the compiler's point of view is not relevant and should not be conflated with the language feature. To the extent that you have to think about the implementation mechanics of the language feature, the implementation mechanics are lacking. Ideally you wouldn't have to consider them. |
I agree. However, to the compiler that distinction is important. As it stands the compiler has no knowledge of how You and I probably agree that this case is likely pathological and unrealistic. But that seems to be the primary argument against #16869 and having the compiler treat a tuple literal/deconstruction as shorthand for simple assignments. And as such that would have to be the primary argument against this proposal. |
Yes. I strongly believe that the theory around ValueTuple as implementation mechanism for tuples should be to serve the language feature at the expense of treating ValueTuple like a normal type and caring about observable side effects of optimizations. No one will implement their own ValueTuple except to cater to this language feature, and we shouldn't go out of our way to allow ValueTuple to break the principles of the language feature. |
Relates to #1580 (support for warning waves) |
Fixed by #18937 (this will ship in dev15.3) |
Version Used: 4fa6e3f
Steps to Reproduce:
Expected Behavior:
warning CS1717: Assignment made to same variable; did you mean to assign something else?
Actual Behavior:
No warnings.
The text was updated successfully, but these errors were encountered: