IDE0200 (remove unnecessary lambda expression) can change semantics when capturing writable members
Open
Area-IDE
Bug
Feature - IDE0200
help wanted
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
**Version Used**:
**Steps to Reproduce**:
```csharp
public class Test {
private List _list = [1];
public bool N() {
var func = M();
_list = [2];
return func(2);
}
private Func 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
Contributor guide
Assessment
This issue has not been assessed yet.