Fix false positive in MissedSelectOpportunity when foreach body uses await#21708
Draft
Fix false positive in MissedSelectOpportunity when foreach body uses await#21708
MissedSelectOpportunity when foreach body uses await#21708Conversation
Agent-Logs-Url: https://github.com/github/codeql/sessions/3e8f4320-2bf4-45f5-b9ea-dad41d522d84 Co-authored-by: hvitved <3667920+hvitved@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix false positive for missed opportunity to use Select with C#
Fix false positive in Apr 14, 2026
MissedSelectOpportunity when foreach body uses await
| @@ -0,0 +1 @@ | |||
| Linq/MissedSelectOpportunity.ql | |||
Copilot stopped work on behalf of
hvitved due to an error
April 14, 2026 09:30
hvitved
requested changes
Apr 14, 2026
| @@ -0,0 +1 @@ | |||
| Linq/MissedSelectOpportunity.ql | |||
Contributor
There was a problem hiding this comment.
Should use inline test expectations, i.e.
postprocess:
- utils/test/InlineExpectationsTestQuery.ql
This also means adding // $ Alert marker comment in the test file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
cs/linq/missed-selectquery incorrectly flaggedforeachloops whose first statement usedawait— loops that cannot be refactored to.Select(...)since LINQ'sSelectoperates onIEnumerable<T>and does not support async lambdas.Changes
csharp/ql/lib/Linq/Helpers.qll: Added exclusion tomissedSelectOpportunity— the predicate no longer holds when the first statement's initializer contains anAwaitExpr. Updated doc comment accordingly.csharp/ql/test/query-tests/Linq/MissedSelectOpportunity/: New test covering:await(should not be flagged)