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

No dead code warnings in variable initializers #49701

Closed
bwilkerson opened this issue Aug 18, 2022 · 1 comment
Closed

No dead code warnings in variable initializers #49701

bwilkerson opened this issue Aug 18, 2022 · 1 comment
Assignees
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request

Comments

@bwilkerson
Copy link
Member

Given the following code:

Never f() { throw ''; }

class C {
  static final x = [1, 2, f(), 4];
}

var x = [1, 2, f(), 4];

I would expect to see the 4's marked as dead code, but the aren't. They do get marked if you place the last line inside a top-level function.

@bwilkerson bwilkerson added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Aug 18, 2022
@stereotype441
Copy link
Member

I believe the reason there's no dead code warning is that the analyzer doesn't create an instance of the FlowAnalysis class when evaluating top level initializers. In retrospect, that was a mistake--it totally should (and it would improve null safety; there's a bunch of analyzer code that currently has to check whether flow analysis is null; that would go away).

@scheglov scheglov added the P3 A lower priority bug or feature request label Aug 19, 2022
@stereotype441 stereotype441 self-assigned this Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request
Projects
None yet
Development

No branches or pull requests

3 participants