Skip to content

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

Open
@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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Area: CFG/SECFG and SE related issues.Type: SEImprove SE engine

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions