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

Allow @doNotStore on callback parameters #45895

Open
nex3 opened this issue May 3, 2021 · 4 comments
Open

Allow @doNotStore on callback parameters #45895

nex3 opened this issue May 3, 2021 · 4 comments
Labels
analyzer-warning Issues with the analyzer's Warning codes area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug

Comments

@nex3
Copy link
Member

nex3 commented May 3, 2021

It would be useful to be able to apply the @doNotStore annotation to parameters passed to callbacks in method signatures. This would allow implementations of methods that call these callbacks to provide parameters that are only valid during the lifetime of the callback, such as views on collections that are later changed after the callback returns.

@nex3 nex3 added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. type-enhancement A request for a change that isn't a bug labels May 3, 2021
@scheglov scheglov added the P2 A bug or feature request we're likely to work on label May 5, 2021
@scheglov
Copy link
Contributor

scheglov commented May 5, 2021

@pq @bwilkerson

@pq
Copy link
Member

pq commented May 5, 2021

Sounds reasonable to me. Thanks @nex3!

@jefflim-google: curious if this use case has come up at all for you?

@jefflim-google
Copy link

TBH, it sounds like something that could be useful, but hasn't come up as a case we've thought about so far.

@matanlurey
Copy link
Contributor

I could give you an example @jefflim-google:

class Button {
  final void Function(@doNotStore UIContext) onPress;

  Button({this.onPress});
}

I'd love for this to trigger a lint:

UIContext store;

Button({
  onPress: (context) {
    // LINT: do_not_store
    store = context;
  }
});

@srawlins srawlins added the analyzer-warning Issues with the analyzer's Warning codes label Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-warning Issues with the analyzer's Warning codes area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

6 participants