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

Lint that flags uses of Map, Set, or List with keys outside the domain of the type #58604

Closed
Hixie opened this issue Jan 1, 2022 · 2 comments
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.

Comments

@Hixie
Copy link
Contributor

Hixie commented Jan 1, 2022

According to #48030, it's intentional that you can do things like:

  Map<String, int> foo = {};
  // ...
  print(foo[2]); // prints null, since foo cannot possibly contain an entry with key 2

It would be nice if that tripped a lint to warn you that you're doing something almost certainly invalid.

This would apply to all the methods and operators on the container classes that are defined to take Object? instead of K.

@parlough
Copy link
Member

parlough commented Jan 1, 2022

Related: #57844 and #58427

@srawlins
Copy link
Member

Duplicate of #58427 and #57434 and #57844

@devoncarew devoncarew added analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Nov 19, 2024
@devoncarew devoncarew transferred this issue from dart-lang/linter Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.
Projects
None yet
Development

No branches or pull requests

4 participants