Reporter |
|
---|---|
Created | Jan 19, 2010 7:29:20 PM |
Updated | Apr 6, 2018 6:51:21 PM |
Subsystem | Quick Fixes |
Assignee | Alisa Afonina (alisa.afonina) |
Priority | Major |
State | Submitted |
Type | Bug |
Fix version | 2018.2 |
Affected versions | 2018.1 |
Fixed In Version ReSharper | Undefined |
VsVersion | All Versions |
Consider following test code (simplified version of original code):
); i is highlighted with wavy line and warning "Access to modified closure" is shown.
If copy to local variable fix is chosen code is transformed to:
which breaks original logic. I believe fixed code should look like following snippet:
...
List<int> list = new List<int>();
for (int i = 0; i < list.Count; i++)
{
InvokeAction(() => list.RemoveAt(i--));
}
...
protected void InvokeAction(Action method)
{
if (InvokeRequired)
Invoke(method);
else
method();
}
in list.RemoveAt(*+i+*--)
If copy to local variable fix is chosen code is transformed to:
List<int> list = new List<int>();
for (int i = 0; i < list.Count; i++)
{
int i1 = i;
InvokeAction(() => list.RemoveAt(i1--));
}
which breaks original logic. I believe fixed code should look like following snippet:
List<int> list = new List<int>();
for (int i = 0; i < list.Count; i++)
{
int i1 = i--;
InvokeAction(() => list.RemoveAt(i1));
}