dotnet/roslyn

IDE0200 (remove unnecessary lambda expression) can change semantics when capturing writable members

Open

#73,259 建立於 2024年4月29日

在 GitHub 查看
 (6 留言) (3 反應) (0 負責人)C# (4,257 fork)batch import
Area-IDEBugFeature - IDE0200help wanted

倉庫指標

Star
 (20,414 star)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 256 個 PR)

描述

Version Used:

Steps to Reproduce:

public class Test {
  private List<int> _list = [1];

  public bool N() {
    var func = M();
    _list = [2];
    return func(2);
  }

  private Func<int, bool> M() {
    return x => _list.Contains(x); // IDE0200
  }
}

Diagnostic Id: IDE0200

Expected Behavior: The code fix should not be offered. It changes the semantics.

Actual Behavior: After applying the code fix, N returns false instead of true

I saw that this was fixed when capturing locals in #69101

貢獻者指南