Misdecompilation of a lazy initialization pattern

Abierto
#4,349 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@siegfriedpammer ya está trabajando en esto.

Desde el 16/11/2026.

  • #4352 de @menes97 — cerrado sin fusionar
  • #4354 de @siegfriedpammer — abierto

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
20/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
csharp
Área
compilers

Línea de trabajo

The report is precise: the Release-mode IL for _func ?? (_func = DefFunc) decompiles as => DefFunc, so operations are dropped. First reproduce by building the snippet with dotnet build -c Release and decompiling the assembly, then compare the IL of Func against the decompiled C# to see which null-coalescing and assignment nodes disappear. The work then sits in ILSpy's decompiler transformation pipeline (ICSharpCode.Decompiler), where the delegate-typed ?? pattern is not recognized; done means the round-trip output keeps the read of and assignment to _func. Expect to read the existing transform/pattern-matching stages before changing anything, and add a regression test case for this pattern.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Bug Decompiler

A specific combination of delegates, null-coalescing operator, assignment expression and compiling in Release configuration causes decompiler to lose some operations. This pattern seems to be broken only for delegates. It is not limited to getters as in example below, the pattern is broken in general.

Input code

Compiled with dotnet build -c Release.

internal class Bug
{
    private Action _func;
    
    public Action Func => _func ?? (_func = DefFunc);
    
    private void DefFunc() {}
}
Erroneous output
internal class Bug
{
    private Action _func;

    public Action Func => DefFunc;

    private void DefFunc()
    {
    }
}

Func is decompiled without null-coalescing read from or assignment to _func.

Details
  • ILSpy version: 11.2.0.10050+c86190ef4e24f3137c13a9275316042842d2fada
  • Dotnet SDK: 10.0.401
Lenguaje dominante
C#
Estrellas
27.1k
Forks
3.8k
Merge medio
1 d 23 h
PR fusionados (30 d)
44

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de icsharpcode/ILSpy

Todos los issues de icsharpcode/ILSpy

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.