IEnumerable.Select is replaced with Enumerable.Select if predicate is empty. Same happens to .Zip() and .OrderBy() but not to .Where().
It seems to be depended on the extension method used afterwards, while .Sum() and .Max() cause this bug, .Count() does not.
Tested with different numeric types, resulting in the same issue.
Also one generic type parameter is missing from the methods so it does not compile, e.g. .Select needs two but only has one or .Zip needs three but only has two.
VB.Net input code
Public Class TestClass
Public Shared Sub Test()
Dim intCol = New Integer() {1, 2, 3}
Dim intCol2 = New Integer() {1, 2, 3}
Dim intColQuery = intCol.Select(Function(x) x)
Dim intColCopy = intCol.Select(Function(x) x).ToArray()
Dim intSum = intCol.Select(Function(x) x).Sum(Function(x) x)
Dim intMax = intCol.Select(Function(x) x).Max(Function(x) x)
Dim intCnt = intCol.Select(Function(x) x).Count(Function(x) x > 1)
Dim intSum2 = intCol.Select(Function(x) x).Sum()
Dim intMax2 = intCol.OrderBy(Function(x) x).Max()
Dim intCnt2 = intCol.Select(Function(x) x).Count()
Dim intSum3 = intCol.Zip(intCol2, Function(x, y) x + y).Sum()
End Sub
End Class
Erroneous output
public class TestClass
{
public static void Test()
{
int[] intCol = new int[] { 1, 2, 3 };
int[] intCol2 = new int[] { 1, 2, 3 };
var intColQuery = intCol.Select(x => x);
int[] intColCopy = intCol.Select(x => x).ToArray();
int intSum = intCol.Select(x => x).Sum(x => x);
int intMax = intCol.Select(x => x).Max(x => x);
int intCnt = intCol.Select(x => x).Count(x => x > 1);
var intSum2 = Enumerable.Select<int>((IEnumerable<int>)intCol, x => x).Sum();
var intMax2 = Enumerable.OrderBy<int>((IEnumerable<int>)intCol, x => x).Max();
int intCnt2 = intCol.Select(x => x).Count();
var intSum3 = Enumerable.Zip<int, int>((IEnumerable<int>)intCol, (IEnumerable<int>)intCol2, (x, y) => x + y).Sum();
}
}
Expected output
public class TestClass
{
public static void Test()
{
int[] intCol = new int[] { 1, 2, 3 };
int[] intCol2 = new int[] { 1, 2, 3 };
var intColQuery = intCol.Select(x => x);
int[] intColCopy = intCol.Select(x => x).ToArray();
int intSum = intCol.Select(x => x).Sum(x => x);
int intMax = intCol.Select(x => x).Max(x => x);
int intCnt = intCol.Select(x => x).Count(x => x > 1);
int intSum2 = intCol.Select(x => x).Sum();
int intMax2 = intCol.OrderBy(x => x).Max();
int intCnt2 = intCol.Select(x => x).Count();
int intSum3 = intCol.Zip(intCol2, (x, y) => x + y).Sum();
}
}
Details
- Product in use: VS extension
- Version in use: 9.2.6.0
IEnumerable.Select is replaced with Enumerable.Select if predicate is empty. Same happens to .Zip() and .OrderBy() but not to .Where().
It seems to be depended on the extension method used afterwards, while .Sum() and .Max() cause this bug, .Count() does not.
Tested with different numeric types, resulting in the same issue.
Also one generic type parameter is missing from the methods so it does not compile, e.g. .Select needs two but only has one or .Zip needs three but only has two.
VB.Net input code
Erroneous output
Expected output
Details