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

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

Open
mary-georgiou-sonarsource opened this issue Aug 12, 2024 · 0 comments
Labels
Area: CFG/SE CFG and SE related issues. Type: SE Improve SE engine

Comments

@mary-georgiou-sonarsource
Copy link
Contributor

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.

@mary-georgiou-sonarsource mary-georgiou-sonarsource added the Area: CFG/SE CFG and SE related issues. label Aug 12, 2024
@mary-georgiou-sonarsource mary-georgiou-sonarsource changed the title LVA: Learn more constraints when learning from FirstOrDefault, LastOrDefault and SingleOrDefault SE: Learn more constraints when learning from FirstOrDefault, LastOrDefault and SingleOrDefault Aug 14, 2024
@mary-georgiou-sonarsource mary-georgiou-sonarsource added the Type: SE Improve SE engine label Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: CFG/SE CFG and SE related issues. Type: SE Improve SE engine
Projects
None yet
Development

No branches or pull requests

1 participant