Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Tragetaschen opened this issue Apr 29, 2024 · 0 comments
Labels
Area-IDE Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Projects
Milestone

Comments

@Tragetaschen
Copy link

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

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 29, 2024
@CyrusNajmabadi CyrusNajmabadi added Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 29, 2024
@CyrusNajmabadi CyrusNajmabadi added this to the Backlog milestone Apr 29, 2024
@CyrusNajmabadi CyrusNajmabadi added this to InQueue in Small Fixes via automation Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE Bug help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Projects
Small Fixes
  
InQueue
Development

No branches or pull requests

2 participants