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

Compilation error after applying quick fix for prefer_is_empty linter rule #55250

Closed
aemelyanovff opened this issue Mar 20, 2024 · 1 comment
Closed
Assignees
Labels
analyzer-quick-fix 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

Comments

@aemelyanovff
Copy link

aemelyanovff commented Mar 20, 2024

Consider this code:

bool isEmptyNotNull(List<String>? nullableList) {
  return nullableList?.length == 0;
}

The prefer_is_empty linter report reports a warning: Use 'isEmpty' instead of 'length' to test whether the collection is empty. Try rewriting the expression to use 'isEmpty'. When you apply the proposed fix, e.g. by running dart fix --apply, the result is

bool isEmptyNotNull(List<String>? nullableList) {
  return nullableList.isEmpty;
}

which fails to compile with The property 'isEmpty' can't be unconditionally accessed because the receiver can be 'null'.

Expected behavior: if code compiles before dart fix then it should compile after.

  • Dart version and tooling diagnostic info (dart info): 3.3.0 (stable) (Tue Feb 13 10:25:19 2024 +0000) on "macos_arm64"
  • Whether you are using Windows, macOS, or Linux (if applicable): macOS
  • Whether you are using Chrome, Safari, Firefox, Edge (if applicable): N/A
@lrhn lrhn added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Mar 20, 2024
@pq pq added P2 A bug or feature request we're likely to work on analyzer-quick-fix labels Mar 22, 2024
@pq pq self-assigned this Mar 22, 2024
@pq
Copy link
Member

pq commented Mar 22, 2024

Great catch and awesome report. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-quick-fix 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
Projects
None yet
Development

No branches or pull requests

3 participants