Understanding type instability related to StructArrays

The problem is that StructArray{Foo} is an abstract type:

julia> isconcretetype(StructArray{Foo})
false

The actual type of a StructArray is complicated:

julia> typeof(StructArray([Foo(1), Foo(2)]))
StructVector{Foo, NamedTuple{(:foo,), Tuple{Vector{Int64}}}, Int64} (alias for StructArray{Foo, 1, NamedTuple{(:foo,), Tuple{Array{Int64, 1}}}, Int64})

So you’re better off using a type parameter:

mutable struct Bar{S <: StructArray{Foo}}
   bar::S
end