Incorrect loop bound in SizeOptIListSelectIterator.ToList
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 64/100
Línea de trabajo
Busca SizeOptIListSelectIterator<TSource, TResult>.ToList() en el código fuente de .NET runtime y lee la implementación del iterador introducida en el PR #118156. Reproduce el problema con <UseSizeOptimizedLinq>true</UseSizeOptimizedLinq> usando el ejemplo de reflexión proporcionado. Se considera terminado cuando el override devuelve los elementos seleccionados y el resultado coincide con la enumeración normal de la consulta; el issue sugiere corregir o eliminar esta ruta no pública.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description
SizeOptIListSelectIterator<TSource, TResult>.ToList() checks the destination list’s Count immediately after constructing it with a capacity. Since Count is zero, the loop never executes and the override returns an empty list for a nonempty source.
Admittedly, this path is non-public and functionally dead, but it hides a ticking time bomb, so would be nice to fix for good hygiene (or remove altogether)
Reproduction Steps
With true
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
IEnumerable<int> query = new[] { 1, 2, 3 }.Select(x => x * 10);
MethodInfo method = query.GetType().GetMethod(
"ToList",
BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly)
?? throw new InvalidOperationException("ToList override not found");
List<int> result = (List<int>)(method.Invoke(query, null)
?? throw new InvalidOperationException("ToList returned null"));
Console.WriteLine(query.GetType().Name);
Console.WriteLine($"Reflection: [{string.Join(", ", result)}]");
Console.WriteLine($"Public API: [{string.Join(", ", query.ToList())}]");
Expected behavior
printing [10, 20, 30], matching enumeration of the query
Actual behavior
prints []
Regression?
The erroneous loop was included when this iterator was introduced in #118156
Known Workarounds
No workaround is needed
Configuration
Windows 10, x64
Reproduced on .NET 10, 11 rc3 and main
Other information
List<TResult> list = new List<TResult>(_source.Count);
for (int i = 0; i < list.Count; i++)
{
list.Add(_selector(_source[i]));
}
return list;
The constructor initializes Capacity, not Count
- Lenguaje dominante
- C#
- Estrellas
- 18.4k
- Forks
- 5.8k
- Merge medio
- 2 d 12 h
- PR fusionados (30 d)
- 579
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de dotnet/runtime
-
DbTransaction.SupportsSavepoints docs say Release/ReleaseAsync are expected to throw, but they are no-ops by designPosiblemente ocupada @alaricd la tomó hace 1 día. Abiertoarea-System.Transactions untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
dotnet/runtime#137040 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
FileSystemGlobbing: Matcher throws ArgumentOutOfRangeException when the rootDir is the same value as the filePosiblemente ocupada @makazeu la tomó hace 1 día. Abiertoarea-Extensions-FileSystem
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
dotnet/runtime#136989 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Configuration binder source generator emits unqualified List<T> when binding arrays without implicit usingsPosiblemente ocupada @makazeu la tomó hace 1 día. Abiertoarea-Extensions-Configuration bug source-generator
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
dotnet/runtime#136972 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[wasi] .NET 10: WasmEnableSIMD with AOT fails because WasiApp.targets has -msimd128 commented outAbiertoarea-Build-mono untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
PropertyChangedEventArgs should have a nice DebuggerDisplayPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertoarea-System.ComponentModel untriaged
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
dotnet/runtime#136608 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de dotnet/runtime
Issues similares
-
needs-triage
Dificultad 1/5 1-3 horas Aptitud para principiantes 76/100
Azure/azure-sdk-for-net#64658 · 1 comentario · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
dotnet/aspnetcore#70370 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
NethermindEth/nethermind#15684 ·
Los mantenedores suelen responder en 1 día
-
area/ai-assistant squad/flyt
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
Altinn/altinn-studio#21798 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
SubtitleEdit/subtitleedit#16699 ·
Los mantenedores suelen responder en 1 día