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

[Nullable] Compiler doesn't consider Where(x => x != null) to be a null check #55667

Closed
maxkoshevoi opened this issue Aug 17, 2021 · 2 comments
Closed
Labels
Area-Compilers Concept-API This issue involves adding, removing, clarification, or modification of an API. Feature Request untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@maxkoshevoi
Copy link

maxkoshevoi commented Aug 17, 2021

Background and Motivation

Improve nullability feature by enabling compiler to understand null checks done through LINQ.

Currently lines 3-9 produce nullable warnings, but shouldn't:

List<string?> list = new() { "a", null };

IEnumerable<string> nonNullableList = list.Where(s => s != null);
string nonNullableValue =             list.First(s => s != null);
nonNullableValue =                    list.Single(s => s != null);

nonNullableList =                     list.Where(s => !string.IsNullOrEmpty(s));
nonNullableValue =                    list.First(s => !string.IsNullOrEmpty(s));
nonNullableValue =                    list.Single(s => !string.IsNullOrEmpty(s));

image

@maxkoshevoi maxkoshevoi added Concept-API This issue involves adding, removing, clarification, or modification of an API. Feature Request labels Aug 17, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Aug 17, 2021
@Dreamescaper
Copy link
Contributor

Related: dotnet/csharplang#3951

@CyrusNajmabadi
Copy link
Member

I believe this is currently working as expected from the compiler perspective (teh dotnet/roslyn repo). We'd need a language change at dotnet/csharplang in order to support this. I'm going to close this out as i believe the corresponding lang issue is already being tracked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Concept-API This issue involves adding, removing, clarification, or modification of an API. Feature Request untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

3 participants