Skip to content

NET-1553 SE: Learn more constraints when learning from FirstOrDefault, LastOrDefault and SingleOrDefault #9634

Closed
@mary-georgiou-sonarsource

Description

In the following case , we should also learn a CollectionConstraint.

void Method(List<string> list)
{
    var first = list.FirstOrDefault();
    // branch into:
    // first: Null, list: Empty
    // first: NotNull, list:NotEmpty
}
void Method(List<string> list)
{
    var first = list.FirstOrDefault(x => x.Length > 5);
    // branch into:
    // first: Null
    // first: NotNull, list: NotEmpty
}

The method that needs to be modified is Invocation.ProcessElementOrDefaultMethods here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions