C#: Don't suggest LINQ re-writes that would capture in, out, or ref parameters in a lambda. - #22541
Draft
michaelnebel wants to merge 6 commits into
Draft
C#: Don't suggest LINQ re-writes that would capture in, out, or ref parameters in a lambda.#22541michaelnebel wants to merge 6 commits into
in, out, or ref parameters in a lambda.#22541michaelnebel wants to merge 6 commits into
Conversation
michaelnebel
force-pushed
the
csharp/linqinoutret
branch
from
September 10, 2026 13:03
bcd2547 to
dda0c72
Compare
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The shared check omits separately modeled ref readonly parameters, allowing another uncompilable lambda rewrite.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review tier: Balanced
Findings: 1
New issues introduced by this change (2)
| Severity | Finding |
|---|---|
csharp/ql/lib/Linq/Helpers.qll — ref readonly parameters are modeled separately by Parameter.isReadonlyRef()… |
|
csharp/ql/lib/Linq/Helpers.qll — Correct the typo and subject-verb agreement in this comment. |
What changed in this PR
Refactors shared LINQ opportunity detection and suppresses invalid lambda rewrites involving by-reference parameters.
Changes:
- Centralizes candidate-expression validation in reusable QL modules.
- Adds regression coverage and a change note.
| File | Description |
|---|---|
csharp/ql/lib/Linq/Helpers.qll |
Refactors detection and excludes by-reference captures. |
csharp/ql/src/change-notes/2026-09-10-missed-linq-inoutref.md |
Documents the analysis improvement. |
csharp/ql/test/query-tests/Linq/MissedAllOpportunity/MissedAllOpportunity.cs |
Adds All regression cases. |
csharp/ql/test/query-tests/Linq/MissedAllOpportunity/MissedAllOpportunity.expected |
Records expected All result. |
csharp/ql/test/query-tests/Linq/MissedAllOpportunity/MissedAllOpportunity.qlref |
Configures the All query test. |
csharp/ql/test/query-tests/Linq/MissedAllOpportunity/options |
Configures All test extraction. |
csharp/ql/test/query-tests/Linq/MissedFirstOrDefaultOpportunity/MissedFirstOrDefaultOpportunity.cs |
Tests ref-parameter suppression. |
csharp/ql/test/query-tests/Linq/MissedSelectOpportunity/MissedSelectOpportunity.cs |
Tests out-parameter suppression. |
csharp/ql/test/query-tests/Linq/MissedWhereOpportunity/MissedWhereOpportunity.cs |
Tests in-parameter suppression. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
michaelnebel
force-pushed
the
csharp/linqinoutret
branch
from
September 10, 2026 14:03
dda0c72 to
65d7e71
Compare
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.


In this PR we
Helpers.qllfor thecs/linq/missed-*queries to enable sharing of logic.in,outorrefparameter is suggested.