Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 24, 2025

The pattern x is not null or "" evaluates as (x is not null) OR (x is ""), incorrectly including empty strings in the filter result. Replaced with !string.IsNullOrEmpty(x) to properly exclude both null and empty strings.

Before:

FrozenSet<string> excludeFiles = files.Where(x => x is not null or "").ToFrozenSet();

After:

FrozenSet<string> excludeFiles = files.Where(x => !string.IsNullOrEmpty(x)).ToFrozenSet();

Related: dotnet/roslyn#75506

To double check:

Original prompt

This section details on the original issue you should resolve

<issue_title>Possible incorrect use of "NOT ... OR ..." pattern</issue_title>
<issue_description>Our internal tools are flagging these blocks of code as potentially improper use of the not ... or ... pattern matching syntax.

FrozenSet<string> excludeFiles = files.Where(x => x is not null or "").ToFrozenSet();

See dotnet/roslyn#75506 for more information on why this pattern is being flagged. If this logic is correct, consider restructuring it to use clarifying () parentheses.</issue_description>

Comments on the Issue (you are @copilot in this section)

@mmitche Yeah, this is solidly wrong. Would be `x is not null and x is not ""`. Better to use `!string.IsNullOrEmpty(x)`.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix possible incorrect use of NOT ... OR ... pattern Fix incorrect "NOT ... OR ..." pattern in LoadExclusions filter Nov 24, 2025
Copilot AI requested a review from mmitche November 24, 2025 19:38
.gitignore Outdated

# vscode python env files
.env
.env.nuget/
Copy link
Member

Choose a reason for hiding this comment

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

@copilot remove this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 4d768ca

@mmitche mmitche marked this pull request as ready for review November 24, 2025 19:57
Copilot AI requested a review from mmitche November 24, 2025 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Possible incorrect use of "NOT ... OR ..." pattern

2 participants