julia> d = Dict(4 => "hola", 5 => "mundo")
Dict{Int64,String} with 2 entries:
4 => "hola"
5 => "mundo"
julia> d["wrong key type"]
ERROR: KeyError: key "wrong key type" not found
Stacktrace:
[1] getindex(::Dict{Int64,String}, ::String) at ./dict.jl:474
I think this should throw a key type error, instead of a key not found error. I have had a few errors of these kind very hard to debug, because I was making the wrong assumption (that I had not added the key into the Dict), instead of focusing on a type mismatch.
A type error here would be more informative. In fact I would expect a “method does not exist” type of error. I don’t understand why getindex(::Dict{K,V}, ::T)
does not require T == K
(the definition should be getindex(::Dict{K,V},::K)
, shouldn’t it?).
Don’t you agree? I will raise an issue I am not missing nothing obvious.