Closed
Description
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]);
}