-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Map operator[] allows any type #48030
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
Comments
Yeah, extending this change to cover the methods as well would make sense too. I think that's similarly likely to always be a programming error, though I can see situations where you might not know the incoming type (e.g. you got something from JSON) and where it might therefore make sense? On the whole I would be biased towards stronger typing here. |
Definitely a deliberate design choice. The reason that A The I believe the original source of that choice was #9893. The only functions that need to prevent you from passing in unrelated values are ones that add to the collection, because the things you add must have the actual key/value/element type. If anything, the odd methods are the query methods Changing this now is a breaking change. |
Fair enough. I'll suggest a lint instead. |
A
Map<K, V>
will never contain a key with a type other thanK
, so it's almost certainly a programming error if the argument toMap.operator[]
is not of typeK
. However,Map.operator[]
takes anObject?
!We should tighten the argument to
Map
, with adart fix
that inserts anas dynamic
to migrate people (we already have a lint that catches use ofdynamic
so people will be warned without being broken).The text was updated successfully, but these errors were encountered: