Misdecompilation of a lazy initialization pattern

オープン
#4,349 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@siegfriedpammer がすでに取り組んでいます。

2026年11月16日 から。

  • #4352 @menes97 による — マージされずにクローズ
  • #4354 @siegfriedpammer による — オープン

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
20/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
csharp
領域
compilers

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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
主要言語
C#
スター
27.1k
フォーク
3.8k
平均マージ
1日 23時間
マージ済み PR(30日)
44

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

icsharpcode/ILSpy のほかの issue

icsharpcode/ILSpy の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。