# Dict key not found instead of type error?

**URL:** <https://discourse.julialang.org/t/dict-key-not-found-instead-of-type-error/4972>\
**Category:** General Usage\
**Tags:** question, proposal\
**Created:** [July 20, 2017, 10:15am UTC](https://discourse.julialang.org/t/dict-key-not-found-instead-of-type-error/4972 "2017-07-20T10:15:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Post date:** [July 20, 2017, 10:15am UTC](https://discourse.julialang.org/t/dict-key-not-found-instead-of-type-error/4972/1 "2017-07-20T10:15:31Z")

</div>

```julia
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.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [July 20, 2017, 10:29am UTC](https://discourse.julialang.org/t/dict-key-not-found-instead-of-type-error/4972/2 "2017-07-20T10:29:07Z")

</div>

No, dict keys are compared using `isequal`.

```julia
julia> Dict(1 => 2)[1.0]
2

```

There is no need to open an issue about this, see e.g. [https://github.com/JuliaLang/julia/issues/15614](https://github.com/JuliaLang/julia/issues/15614)
