CS0177 weird behavior #69057
-
Please consider the following code:
This code generates CS0177 error which I believe should not be generated because if I am not mistaken On the other hand, if I modify the code to look like this:
The CS0177 error goes away, but if I am not mistaken it should be generated because if Please share your thoughts on CS0177 correctness, should this be reported as an issue or not? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 20 replies
-
This is by design. The language doesn't track the relationship between disparate variables. If you would like that, you'll need to start a discussion on csharplang (or add to an existing one). |
Beta Was this translation helpful? Give feedback.
-
Intentionally locking. This question has been asked and answered. The latest responses are all things that should go to dotnet/csharplang instead. Locking this so that that happens and the requests for language changing doing continue happening here. |
Beta Was this translation helpful? Give feedback.
Simplified:
In the first case, there appears to be a non-exceptional codepath where the variable is not assigned. This is because the language doesn't track the relationship between variables, so we don't understand how to use the 'Succeeded' variable to inform things here.
If you want that to be supported, you'll have to make a language changes request.
In the second case, we can see that in all non-exceptional paths it is assigned. And it exceptional paths it isn't(which is 100% ok). This is again working just as spec'ed in the language. There's no indication that there is anything even wrong in this case. This works very much as intended wrt exceptional vs non-exceptional flows. You co…