# Type instability of array getindex

**URL:** https://discourse.julialang.org/t/type-instability-of-array-getindex/126636
**Category:** New to Julia
**Created:** [March 6, 2025, 1:39pm UTC](https://discourse.julialang.org/t/type-instability-of-array-getindex/126636 "2025-03-06T13:39:23Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jacobga](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@jacobga](https://discourse.julialang.org/u/jacobga)
#### Post date: [March 6, 2025, 1:39pm UTC](https://discourse.julialang.org/t/type-instability-of-array-getindex/126636/1 "2025-03-06T13:39:23Z")

</div>

The following example shows that there is a runtime dispatch on accessing an array. Why is that the case, and can I avoid it?

```julia
struct example
    a::Array{Int64}
end

function examplefun(x::example)
    return @inbounds x.a[10]
end

```

```julia
julia> @report_opt examplefun(example([1,2]))
═════ 1 possible error found ═════

│┌ getindex(A::Array{Int64}, i::Int64) @ Base ./essentials.jl:916
││ runtime dispatch detected: Base.throw_boundserror(A::Array{Int64}, %25::Tuple{Int64})
│└────────────────────

```

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [March 6, 2025, 1:49pm UTC](https://discourse.julialang.org/t/type-instability-of-array-getindex/126636/2 "2025-03-06T13:49:53Z")

</div>

array is an abstract type. did you want `Vector{Int}`?

---

<div class="post-metadata">

### Author: ![jacobga](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@jacobga](https://discourse.julialang.org/u/jacobga)
#### Post date: [March 6, 2025, 2:04pm UTC](https://discourse.julialang.org/t/type-instability-of-array-getindex/126636/3 "2025-03-06T14:04:50Z")

</div>

Thank you! That solves it. I was confused thinking Array{Int} was the concrete type of the corresponding AbstractArray abstract type. I see now, I need to use Vector, Matrix, or specify Array dimensions.
