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

Analyzer proposal: mark anonymous functions as static #52840

Closed
xtqqczze opened this issue Apr 16, 2021 · 5 comments
Closed

Analyzer proposal: mark anonymous functions as static #52840

xtqqczze opened this issue Apr 16, 2021 · 5 comments
Labels
Area-Analyzers Area-IDE Feature Request help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Milestone

Comments

@xtqqczze
Copy link

Cause

An anonymous function that does not capture state from the enclosing scope is not marked as static.

Rule description

Lambdas and anonymous methods can be marked with the static modifier, to disallow capture of locals or instance state. Adding the static modifier to an anonymous function does not change the meaning of the program.

By applying this code fix, it can be ensured that future modifications to a program do not result in unexpected retention of captured objects or unexpected additional allocations.

Additional context

@mavasani mavasani transferred this issue from dotnet/roslyn-analyzers Apr 22, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Analyzers untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 22, 2021
@mavasani mavasani added Area-IDE Need Design Review The end user experience design needs to be reviewed and approved. labels Apr 22, 2021
@CyrusNajmabadi
Copy link
Member

We explicitly decided not to do this as it would clutter up code that is intended to be terse unilaterally. static is intentionally intended to be a user controlled system whereby they annotate the lambdas tehy do not want capturing to ensure that no captures exist and no regressions happen in the future. It is not considered a 'better way' to do lambdas, or a pattern we would push people to use for all lambdas (even when applicable).

@NTaylorMullen
Copy link
Contributor

NTaylorMullen commented Apr 26, 2021

Design Meeting Notes:

image

@jinujoseph jinujoseph added this to the Backlog milestone Apr 28, 2021
@jinujoseph jinujoseph added the help wanted The issue is "up for grabs" - add a comment if you are interested in working on it label Apr 28, 2021
@jinujoseph jinujoseph added Feature Request and removed Need Design Review The end user experience design needs to be reviewed and approved. untriaged Issues and PRs which have not yet been triaged by a lead labels May 5, 2021
@Youssef1313
Copy link
Member

@NTaylorMullen based on the design meeting notes, wouldn't it be better to offer it as a refactoring then?

@CyrusNajmabadi
Copy link
Member

I'm not really a fan of refactorings taht do nothing but add a keyword to something. It can just be done manually with very little effort. st<tab> is likely enough.

@CyrusNajmabadi
Copy link
Member

Closing out as not planned.

@CyrusNajmabadi CyrusNajmabadi closed this as not planned Won't fix, can't repro, duplicate, stale Oct 22, 2024
@dotnet dotnet locked and limited conversation to collaborators Oct 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area-Analyzers Area-IDE Feature Request help wanted The issue is "up for grabs" - add a comment if you are interested in working on it
Projects
Status: Complete
Development

No branches or pull requests

6 participants