C#: Remove some FPs for cs/simplifiable-boolean-expression. - #22708
michaelnebel wants to merge 7 commits into
Conversation
… left/right and branches instead of relying on magic constants.
…or equality, logical and conditional operations.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Conditional rewrites still accept non-Boolean or unknown condition types, allowing invalid simplification suggestions.
Review effort: Balanced
Findings: 1
Open (2)
What changed in this PR
Reduces false positives in C# Boolean-expression simplification when type information is incomplete or nullable.
Changes:
- Requires Boolean operand types before suggesting rewrites.
- Adds nullable and incomplete-type regression cases.
- Adds a change note.
| File | Description |
|---|---|
csharp/ql/src/Language Abuse/SimplifyBoolExpr.ql |
Adds type-aware rewrite predicates. |
csharp/ql/test/query-tests/Language Abuse/SimplifyBoolExpr/SimplifyBoolExpr.cs |
Tests nullable Boolean comparison. |
csharp/ql/test/query-tests/standalone/Language Abuse/SimplifyBoolExpr/SimplifyBoolExpr.cs |
Tests incomplete type information. |
csharp/ql/src/change-notes/2026-09-30-simplify-bool-expr.md |
Documents reduced false positives. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
Review effort: Lite
Findings: 1
Open (3)
These statements referencecontainerwithout any declaration, which can introduce cascading… · New The BoolType gating logic is duplicated across binary and conditional rewrites. Consider factoring… · New The BoolType gating logic is duplicated across binary and conditional rewrites. Consider factoring… · New


It turns out that the query
cs/simplifiable-boolean-expressionproduces some false positives, when the extracted data has incomplete type information.The following example produces a false positive
If type information had been complete, for instance
then the query didn't produce an alert prior to the changes in this PR. In this case an alert is NOT produced because the boolean literal
trueon the right hand side of==is wrapped in a cast.