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

Issue warning when indexing Map<K, V> with type other than K #58176

Closed
averynortonsmith opened this issue May 29, 2020 · 1 comment
Closed

Issue warning when indexing Map<K, V> with type other than K #58176

averynortonsmith opened this issue May 29, 2020 · 1 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. linter-lint-request type-enhancement A request for a change that isn't a bug

Comments

@averynortonsmith
Copy link

The operator [] method for a map of type Map<K, V> has the type V operator [](Object key); that is, it permits keys of any type. However, accessing a map with a key type other than K often indicates the presence of a bug. It would be helpful to have a linter rule that detects these situations.

In the following example, the new rule would create a warning about the expression m[false], since m will never contain keys of type bool:

void main() {
  Map<int, String> m = {1: "a"};
  print(m[false]);
}
@averynortonsmith averynortonsmith added type-enhancement A request for a change that isn't a bug linter-lint-request labels May 29, 2020
@srawlins
Copy link
Member

I think this should be covered by #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 18, 2024
@devoncarew devoncarew transferred this issue from dart-lang/linter Nov 18, 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. linter-lint-request type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants