Thanks Jameson and here the context:
# Initializes an array which has a's container but b's eltype
function f(a::AbstractVector, b::AbstractVector)
Eb = eltype(b) # this is type-stable
Ca = typeof(a).name.primary # this is not type-stable
return Ca(Eb, 5) # assumes Ca supports the normal Array constructor
end
The last line would probably better use copy+convert but for that I
still need to make Ca{Eb,1}. Note that Ca is always a leaftype and I
don't want to climb the type hierarchy, so I think your remark about the
subtypes does not apply.
Here the typed code:
julia> @code_warntype f([1,2], [1.])
Variables:
a::Array{Int64,1}
b::Array{Float64,1}
Eb::Type{Float64}
Ca::Type{T} # <---
Body:
begin # none, line 3:
Eb = Float64 # line 4:
Ca = (top(getfield))((top(getfield))(typeof(a::Array{Int64,1})::Type{Array{Int64,1}},:name)::TypeName,:primary)::Type{T} # line 5:
return (Ca::Type{T})(Eb::Type{Float64},5)::Any
end::Any
Thanks!