Open
Description
openedon Jan 22, 2018
On Version 0.7.0-DEV.3424, Commit 6afcb045b5
(and also on 0.6)
struct A
b::Int
c::Float64
end
As = [A(0,0) for i=1:10]
for idxs in [[1], []]
println(ifelse(length(idxs)==0, "empty", "full"))
@show eltype([getfield(a, :b) for a in As[idxs]]) # same as eltype([a.b for a in As[idxs]])
@show eltype([getfield(a, :c) for a in As[idxs]]) # same as eltype([a.c for a in As[idxs]])
@show eltype(getfield.(As[idxs], :b))
@show eltype(getfield.(As[idxs], :c))
end
produces
full
eltype([getfield(a, :b) for a = As[idxs]]) = Int64
eltype([getfield(a, :c) for a = As[idxs]]) = Float64
eltype(getfield.(As[idxs], :b)) = Int64
eltype(getfield.(As[idxs], :c)) = Float64
empty
eltype([getfield(a, :b) for a = As[idxs]]) = Int64
eltype([getfield(a, :c) for a = As[idxs]]) = Float64
eltype(getfield.(As[idxs], :b)) = Union{Float64, Int64}
eltype(getfield.(As[idxs], :c)) = Union{Float64, Int64}
(the Union
is unexpected)
I guess inference still works on getfield
, even though it's type-unstable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment