Skip to content

join_return_with_assignment false positive #57915

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

Open
jakemac53 opened this issue Feb 27, 2019 · 2 comments
Open

join_return_with_assignment false positive #57915

jakemac53 opened this issue Feb 27, 2019 · 2 comments
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-linter Issues with the analyzer's support for the linter package linter-false-positive P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@jakemac53
Copy link
Contributor

Describe the issue

join_return_with_assignment reports an error for some cases where the assigned variable is used inside of the same assignment block (generally in a lambda).

To Reproduce

Here is a somewhat contrived example but similar to the case I ran into:

Stream foo() {
  StreamController controller;
  controller = StreamController(onListen: () {
    // controller needs to be assigned or you get a null ptr exception here.
    someOtherStream.listen(controller.add);
  });
  return controller.stream;
}

Expected behavior

The lint would not warn about this code since controller is used after assignment (although its admittedly a bit difficult to tell here).

@pq
Copy link
Member

pq commented Feb 28, 2019

Thanks for this repro @jakemac53 !

@pq pq added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Feb 28, 2019
@srawlins
Copy link
Member

srawlins commented Sep 4, 2022

I think this might be very tricky to implement. For example assigning to a field requires care:

class C {
  late StreamController controller;
Stream foo() {
  controller = StreamController(onListen: () {
    // controller needs to be assigned or you get a null ptr exception here.
    someOtherStream.listen(controller.add); // _this_ controller.
    someOtherStream.listen(otherC.controller.add); // But _not this_ controller.
  });
  return controller.stream;
}

@srawlins srawlins added the P3 A lower priority bug or feature request label Sep 22, 2022
@devoncarew devoncarew added devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. labels Nov 18, 2024
@devoncarew devoncarew transferred this issue from dart-archive/linter Nov 18, 2024
@bwilkerson bwilkerson added area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. and removed legacy-area-analyzer Use area-devexp instead. labels Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-linter Issues with the analyzer's support for the linter package linter-false-positive P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

5 participants