Issue warning when indexing Map<K, V> with type other than K #58176
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
The
operator []
method for a map of typeMap<K, V>
has the typeV operator [](Object key)
; that is, it permits keys of any type. However, accessing a map with a key type other thanK
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]
, sincem
will never contain keys of typebool
:The text was updated successfully, but these errors were encountered: