Resharper expression expression is always incorrect using LINQ Aggregate with seed

In the following code, Resharper states that the expression is currMax == nullalways incorrect.

public Read Read1
{
    get
    {
        return Reads.Where(read => !read.IsIndex)
                    .Aggregate((Read)null, (currMax, read) => currMax == null || read.Length > currMax.Length ? read : currMax);
    }
}

When the first iteration of the lambda expression in the call Aggregateis done, I expect it to currMax == nullbe true, since it (Read)nullis a seed. Resharper knows that the upstream Whererequires non-zero Readobjects in the resulting IEnumerable, because I am accessing a IsIndexclass property Read. Does the resrarper parameter only change the seed parameter to Aggregate?

Edit: here I posted a bug report https://youtrack.jetbrains.com/issue/RSRP-443055

+4
source share
2 answers

, ReSharper , Aggregate ILSpy.

public static TAccumulate Aggregate<TSource, TAccumulate>(
    this IEnumerable<TSource> source, 
    TAccumulate seed, 
    Func<TAccumulate, TSource, TAccumulate> func)
{
    if (source == null)
    {
        throw Error.ArgumentNull("source");
    }
    if (func == null)
    {
        throw Error.ArgumentNull("func");
    }
    TAccumulate tAccumulate = seed;
    foreach (TSource current in source)
    {
        tAccumulate = func(tAccumulate, current);
    }
    return tAccumulate;
}

, null .

+1

ReSharper. YouTrack?

// ReSharper disable once ConditionIsAlwaysTrueOrFalse.

+1

All Articles