# TypeError: in typeassert in Julia 1.6.3

**URL:** <https://discourse.julialang.org/t/typeerror-in-typeassert-in-julia-1-6-3/69946>\
**Category:** General Usage\
**Tags:** question, error, dictionary\
**Created:** [October 17, 2021, 8:31pm UTC](https://discourse.julialang.org/t/typeerror-in-typeassert-in-julia-1-6-3/69946 "2021-10-17T20:31:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![daneshvar.amrollahi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daneshvar.amrollahi/32/30018_2.png) [@daneshvar.amrollahi](https://discourse.julialang.org/u/daneshvar.amrollahi)\
**Post date:** [October 17, 2021, 8:31pm UTC](https://discourse.julialang.org/t/typeerror-in-typeassert-in-julia-1-6-3/69946/1 "2021-10-17T20:31:49Z")

</div>

I am new to Julia. I am working on a Julia package which the writer is not available.

This is the part of the code where I have a problem with:

```julia
function find_partition(model::Model, ms)
    ps = Dict{Z3Expr,Vector{Int}}()
    for (i, m) in enumerate(ms)
        mval = Z3.eval(model, m, false)
        println(ps)
        println(mval)
        println(typeof(mval))
        if haskey(ps, mval)
            push!(ps[mval], i)
        else
            push!(ps, mval=>Int[i])
        end
    end
    values(ps)
end

```

Here is the output:

```julia
Dict{Z3.Expr, Vector{Int64}}()
1.0
Z3.ExprAllocated
ERROR: TypeError: in typeassert, expected UInt64, got a value of type UInt32
Stacktrace:
  [1] hashindex(key::Z3.ExprAllocated, sz::Int64)
    @ Base ./dict.jl:169
  [2] ht_keyindex(h::Dict{Z3.Expr, Vector{Int64}}, key::Z3.ExprAllocated)
    @ Base ./dict.jl:284
  [3] haskey(h::Dict{Z3.Expr, Vector{Int64}}, key::Z3.ExprAllocated)
    @ Base ./dict.jl:550
  [4] find_partition(model::Z3.ModelAllocated, ms::Vector{Z3.ExprAllocated})
    @ Absynth.NLSat ~/Desktop/faoc/Absynth/src/nlsat/cfinitesolver.jl:101

```

I tried following it and found out that somewhere inside `dict.jl` in Julia, there are such lines

```julia
sz = length(h.keys)
...
index = hashindex(key, sz)

```

And this is the hashindex written somewhere in dict.jl:

```julia
hashindex(key, sz) = (((hash(key)::UInt % Int) & (sz-1)) + 1)::Int

```

It seems that the version of Z3 used in this package is not compatible with the current version of Julia. I am not sure if this package was working in the beginning at all.

Is there any quick fix to this? Like rewriting this part of the code:

```julia
if haskey(ps, mval)
     push!(ps[mval], i)
else
     push!(ps, mval=>Int[i])

```

in a way that this won’t happen? I tried writing like `merge!(ps,Dict(mval=>Int[i]))` but it’s eventually reaching this hashindex function again. If I install the older versions of Julia, would it be possible to solve this issue or the problem is somewhere else?

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [October 17, 2021, 8:39pm UTC](https://discourse.julialang.org/t/typeerror-in-typeassert-in-julia-1-6-3/69946/2 "2021-10-17T20:39:45Z")

</div>

Hi Daneshvar,

unfortunately there is no minimal (not) working example I could get my hands dirty on. Please see [Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757)

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [October 17, 2021, 8:45pm UTC](https://discourse.julialang.org/t/typeerror-in-typeassert-in-julia-1-6-3/69946/3 "2021-10-17T20:45:29Z")

</div>

BTW, this thread is tri(?)plicated. And I don’t think it belongs to ‘Internals & Design’.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [October 17, 2021, 9:30pm UTC](https://discourse.julialang.org/t/typeerror-in-typeassert-in-julia-1-6-3/69946/4 "2021-10-17T21:30:42Z")

</div>

I’ve archived the other two copies of this topic (please don’t post the same thing multiple times; it’s also posted on stackoverflow) and moved it into the general usage category.

---

<div class="post-metadata">

**Author:** ![jebej](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jebej/32/1784_2.png) [@jebej](https://discourse.julialang.org/u/jebej)\
**Post date:** [October 18, 2021, 12:30am UTC](https://discourse.julialang.org/t/typeerror-in-typeassert-in-julia-1-6-3/69946/5 "2021-10-18T00:30:28Z")

</div>

The problem is that the `hash(key::Z3.ExprAllocated)` method returns a `UInt32` instead of a `UInt64`. This is why the type assertion fails.

Check in the package code to see if that method is defined and if so you’ll have to fix it. Otherwise, it might be due to a default method of `hash` (though I haven’t checked, I’m not sure there even is a default method for `hash`), in which case you should define your own.

---

<div class="post-metadata">

**Author:** ![daneshvar.amrollahi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/daneshvar.amrollahi/32/30018_2.png) [@daneshvar.amrollahi](https://discourse.julialang.org/u/daneshvar.amrollahi)\
**Post date:** [October 18, 2021, 2:21pm UTC](https://discourse.julialang.org/t/typeerror-in-typeassert-in-julia-1-6-3/69946/6 "2021-10-18T14:21:58Z")

</div>

Thank you for the reply. I tested it with Julia 1.4.2 instead of 1.6.3 and it’s working.
