Skip to content
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

CS8602 should look deeper ("Dereference possibly null reference") #74797

Closed
JVimes opened this issue Aug 18, 2024 · 3 comments
Closed

CS8602 should look deeper ("Dereference possibly null reference") #74797

JVimes opened this issue Aug 18, 2024 · 3 comments
Labels
Area-IDE Feature Request untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@JVimes
Copy link

JVimes commented Aug 18, 2024

Brief description:

CS8602 seems to have a lot of false positives. Suggest making it look deeper to see if value could actually be null.

2024-08-18_13h44_27

Languages applicable:

C#
Not sure on VB.

Code example that the analyzer should [not] report:

var text = "foo";
var notNull = text != null;
if (notNull)
{
    var length = text.Length;
}

Additional information:

I vaguely recall that the analzyers used to look deeper to see if a reference could actually be null. Didn't that used to be the case?

Documentation requirements:

N/A

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Aug 18, 2024
@huoyaoyuan
Copy link
Member

This is by design. All the nullable features only take account for expressions directly inside the if statement. Boolean variables are never propagated. See also #27011 #66807 .

Also note that nullable analysis isn't "analyzer". It is a part of core compiler/language and uses CSxxxx id.

@JVimes
Copy link
Author

JVimes commented Aug 19, 2024

@Hyleon-Ou Thank you. Are requests for design changes accepted, or not really?

@huoyaoyuan
Copy link
Member

It's unlikely to be changed, because more deep analysis may have unconstrained overhead.

@JVimes JVimes closed this as completed Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Feature Request untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

2 participants