Skip to content

CS8604 false positive 'possible null reference argument' when null is excluded in a query. #59172

@MGRussell

Description

@MGRussell

Version Used:
6.0.1

Steps to Reproduce:

    class SomeClass
    {
        public string? SomeNullableString { get; set; }
    }

    void Foo()
    {
        List<SomeClass> list = new List<SomeClass>();

        var query =
            from item in list
            where item.SomeNullableString != null
            select Bar(item.SomeNullableString);
    }

    string Bar(string someNonNullableString)
    {
        return someNonNullableString;
    }

Expected Behavior:
The select Bar(item.SomeNullableString); line should not have a CS8604 warning for the item.SomeNullableString parameter.

Actual Behavior:
It does have such warning.

This is similar to a number of other issues such as #59152 but still independently distinct as I'm not seeing an issue related specifically to query expressions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-CompilersResolution-By DesignThe behavior reported in the issue matches the current designuntriagedIssues and PRs which have not yet been triaged by a lead

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions