Skip to content

C#: Fix bug in guards logic for foreach loops#4165

Merged
hvitved merged 2 commits intogithub:mainfrom
hvitved:csharp/foreach-guard
Aug 31, 2020
Merged

C#: Fix bug in guards logic for foreach loops#4165
hvitved merged 2 commits intogithub:mainfrom
hvitved:csharp/foreach-guard

Conversation

@hvitved
Copy link
Contributor

@hvitved hvitved commented Aug 28, 2020

This PR fixes a bug where the guards library incorrectly concluded certain expressions to be non-empty. For example:

void M(string[] args)
{
    foreach (var arg in args)
        ;
    Console.WriteLine(args); // INCORRECT: was considered always empty
}

However, this is still valid:

void M(string[] args)
{
    foreach (var arg in args)
        Console.WriteLine(args); // CORRECT: is always non-empty
}

@hvitved hvitved added the C# label Aug 28, 2020
@hvitved hvitved requested a review from a team as a code owner August 28, 2020 13:25
@hvitved
Copy link
Contributor Author

hvitved commented Aug 31, 2020

CSharp-Differences job: https://jenkins.internal.semmle.com/job/Changes/job/CSharp-Differences/401/. The result changes seem be just "normal wobbliness" and not actually a result of this PR.

Copy link
Contributor

@tamasvajk tamasvajk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hvitved hvitved merged commit 4e963a8 into github:main Aug 31, 2020
@hvitved hvitved deleted the csharp/foreach-guard branch August 31, 2020 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants