Misdecompilation of a lazy initialization pattern

Aperta
#4,349 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@siegfriedpammer ci sta già lavorando.

Dal 16/11/2026.

  • #4352 di @menes97 — chiusa senza merge
  • #4354 di @siegfriedpammer — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
20/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
csharp
Ambito
compilers

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
C#
Stelle
27.1k
Fork
3.8k
Merge medio
1g 23h
PR unite (30g)
44

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di icsharpcode/ILSpy

Tutte le issue di icsharpcode/ILSpy

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.