dotnet / dotnet/roslynator

Suggestion: Access to loop variable in closure

Open
#873 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
3.5k
Forks
294
Avg merge
2h 30m
Merged PRs (30d)
4

Description

If you access loop variable from closure, variable value will change as loop continues.
This can cause unintended behaviour and such accesses are generally discouraged.
It will be helpful if Roslynator have analyzer to warn this.

ReSharper has similar feature:
https://www.jetbrains.com/help/resharper/AccessToForEachVariableInClosure.html

Contributor guide

Open the contributing guide

Research direction

Start by reviewing Roslynator's existing analyzer structure and the issue's ReSharper reference for the expected warning behavior. Identify how closure captures of loop variables are represented and where analyzer tests live; done means the requested cases produce a warning without unrelated diagnostics.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
devtools
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.