-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Roslyn fails to verify [NotNullWhen] contracts in methods returning Nullable<bool> #57649
Comments
@jcouv did we inadvertently do the "call-site" side of this without doing the "declaration" side of it? |
Conditional nullable attributes are only expected to work on The bug here is actually on the call-site. We are not able to analyze the call-site because we only track one or two states (unconditional or conditional respectively), but |
@jcouv Does it mean that the following code should have a warning because the expression #nullable enable
using System.Collections.Generic;
class C
{
public void M(Dictionary<string, string>? dictionary)
{
if (dictionary?.TryGetValue("", out var x) ?? false)
{
x.ToString(); // currently no warning
}
}
} |
@TessenR No, that scenario will continue to work. |
It seems like one solution here is to report a diagnostic for use of |
#36073 is an umbrella issue for reporting warnings on misuse of attributes based on the signature. We do already have some warnings on misuse in terms of what the implementation is doing, as @jaredpar has pointed out in email. For example, when the method has |
Version Used:
Steps to Reproduce:
Compile and run the following code
Expected Behavior:
CS8762: Parameter 'x' must have a non-null value when exiting with 'true'.
reported forreturn true;
inM1
Actual Behavior:
No warnings at all in the program above. It crashes at runtime with a
NullReferenceException
The text was updated successfully, but these errors were encountered: