-
Notifications
You must be signed in to change notification settings - Fork 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
[DoesNotReturn] warning is only reported in nullable-enabled context #5231
Comments
I think the behavior in the issue description is expected. DoesNotReturn is not respected by control flow analysis, definite assignment, etc. Is there some design notes/documentation indicating otherwise? |
Moved the issue to csharplang since it's a language design question. |
Added topic to LDM backlog (when convenient) |
@jcouv like Rikki said, I don't understand what we're trying to ask here. This is the expected behavior of all nullable flow analysis attributes: what else are you expecting to see? |
@333fred Yes, the current behavior is by current design. The ask is to change this design ;-) The proposed change and expectation are described in OP. Unlike other nullability attributes, this one doesn't have anything to do with nullability.
|
This seems about equally sound as definite assignment of void M()
{
int x;
SomeLibrary.M(out x);
x.ToString(); // could still be uninitialized?
} |
It only has to do with nullability. No other part of the language or compiler pays attention to any of these attributes. It does not affect definite assignment in any fashion. I guess I'm not sure what has changed in the past 2 years that we feel we need to revisit this again. |
@jcouv did you have a response to my question above? |
@333fred It's a question for Chuck who's raising the issue. Personally, I am sympathetic to the proposal and simply having more experience with the attributes is a sufficient reason to revisit. |
The attribute indicates only that the method does not return which seems independent of nullability, and the warning " |
I can see this both ways. if (x is null)
{
ADoesNotReturnMethod();
}
_= x.ToString() // no warning. This is the original intent of the attribute. However, from another perspective, it's just a "DoesNotReturn" where I want the compiler to warn me if it's used while the method does return. So whether or not the compiler is using it for nullability analysis is just one side of it. |
Are we comfortable introducing a new error in implementations when DoesNotReturn is applied, but the method does return? That's what would be necessary to meet "definite assignment" standards, but the shipped behavior is only to warn. |
Discussed in LDM 10/13/2021: in short, keep as-is |
In long: we are more interested in investing our efforts into a more powerful, generalized, solution like |
Warning CS8763 should be reported for
F1()
below:The text was updated successfully, but these errors were encountered: