Skip to content

numeric-only zero check, unambiguous overload lookups - #89

Open
koenbeuk wants to merge 1 commit into
mainfrom
fix/loop-conversion-hardening
Open

numeric-only zero check, unambiguous overload lookups#89
koenbeuk wants to merge 1 commit into
mainfrom
fix/loop-conversion-hardening

Conversation

@koenbeuk

@koenbeuk koenbeuk commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

@codecov

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 41.66667% with 14 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ExpressiveSharp/Transformers/ConvertLoopsToLinq.cs 41.66% 13 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Two moderate issues remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

This PR improves ConvertLoopsToLinq numeric-zero detection and LINQ overload selection.

Changes:

  • Narrows numeric constant handling.
  • Disambiguates Where, Select, and Min/Max overloads.
  • Adds regression and overload-selection tests.
File summaries
File Summary and findings
src/ExpressiveSharp/Transformers/ConvertLoopsToLinq.cs Updates zero detection and LINQ method resolution. Moderate (3 votes): Make the guard type-aware and reject nullable/reference defaults before matching Sum.
tests/ExpressiveSharp.Tests/Transformers/ConvertLoopsToLinqTests.cs Adds regression and overload-shape tests. Moderate (1 vote): Add transformer-level assertions covering selected delegate parameter types, including Min/Max selectors.
Review details

Suppressed comments (1)

tests/ExpressiveSharp.Tests/Transformers/ConvertLoopsToLinqTests.cs:325

  • This test only counts Enumerable methods using the same reflection predicate as production; it would pass even if the transformer still used the old unfiltered First, and it never exercises the changed selector-based Min/Max lookup. Add transformer-level assertions that inspect the selected delegate parameter type (including a Min/Max selector case) so the overload-resolution change is actually covered.
        var whereMatches = typeof(Enumerable).GetMethods(BindingFlags.Public | BindingFlags.Static)
            .Count(m => m.Name == "Where" && m.IsGenericMethodDefinition && m.GetParameters().Length == 2
                && m.GetParameters()[1].ParameterType.GetGenericArguments().Length == 2);

        var selectMatches = typeof(Enumerable).GetMethods(BindingFlags.Public | BindingFlags.Static)
            .Count(m => m.Name == "Select" && m.IsGenericMethodDefinition
                && m.GetParameters().Length == 2
                && m.GetGenericArguments().Length == 2
                && m.GetParameters()[1].ParameterType.GetGenericArguments().Length == 2);
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +543 to +547
if (expr is ConstantExpression { Value: not null } constant)
{
return Convert.ToDouble(constant.Value) == 0.0;
return constant.Value switch
{
byte v => v == 0,
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.

2 participants