Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

[Proposal]: Nullable analysis of LINQ queries #3951

Closed
1 of 5 tasks
jcouv opened this issue Sep 28, 2020 · 2 comments
Closed
1 of 5 tasks

[Proposal]: Nullable analysis of LINQ queries #3951

jcouv opened this issue Sep 28, 2020 · 2 comments

Comments

@jcouv
Copy link
Member

jcouv commented Sep 28, 2020

Nullable analysis of LINQ queries

  • Proposed
  • Prototype: Not Started
  • Implementation: Not Started
  • Specification: Not Started

Summary

Nullable analysis of LINQ queries (LDM expressed interested to handle Where, needs design proposal)

Motivation

Range variables in LINQ queries are currently treated as oblivious to minimize annoyances.
Most of the annoyance results from our inability to recognize method calls that filter out null elements, such as .Where(i => i is not null).

using System.Linq;
using System.Collections.Generic;

#nullable enable
public class C 
{
    public void M(IEnumerable<string?> list) 
    {
        _ = from item in list
            select item.ToString(); // should warn

        _ = list
            .Where(i => i is not null)
            .Select(i => i.ToString()); // should not warn
    }
}

Detailed design

TBD

Unresolved questions

  • How to recognize Where methods?

Design meetings

Split issue from #3868
https://github.com/dotnet/csharplang/blob/main/meetings/2022/LDM-2022-09-28.md#nullability-improvements
https://github.com/dotnet/csharplang/blob/main/meetings/2024/LDM-2024-09-06.md#nullable-analysis-of-linq-queries

@gafter
Copy link
Member

gafter commented Dec 16, 2020

Would these warnings only be suppressed for the "standard" Linq implementations that have the expected semantics, or for all query expressions (even those that do not have the expected semantics)?

@JTeeuwissen
Copy link

Note that OfType currently can be used to filter out nulls whilst getting the correct return type. But perhaps there are more cases where this would not apply.

@333fred 333fred modified the milestones: Working Set, Backlog Sep 7, 2024
@dotnet dotnet locked and limited conversation to collaborators Nov 19, 2024
@333fred 333fred converted this issue into discussion #8998 Jan 6, 2025

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

4 participants