Description
This is the same request as #36541 but for a slightly different reason: I'd like a version of Map.operator []
that type-checks the key.
As I mentioned in #57844:
I recently found a bug where I accidentally typed
someMap[someObject]
instead ofsomeMap[someObject.id]
. (operator []=
does use the Map's key type butoperator []
usesObject
.)
Arguably this wouldn't be necessary with #57844, although conceivably one might want strict type-checking without relying on lints being configured. It's also unclear what the timeline might be for implementing that.
(Alternatively, operator []
(and various other functions) could take the key type. I know that the rationale is that asking a collection of K
if it contains something else isn't wrong, but it's not clear to me when it's actually the right thing to do. That is, in what circumstances is that desirable? I've seen some academic examples with questionable real-world utility, whereas the lack of typing is known to cause bugs in real code.)