Hi Pontus, this is a bug. Running it inside vs outside of a function shows the same issue:
julia> @show issubtype(fieldtype(foo, :bar), Array) issubtype(fieldtype(foo,:bar),Array) => true true julia> f() = @show issubtype(fieldtype(foo, :bar), Array) f (generic function with 1 method) julia> f() issubtype(fieldtype(foo,:bar),Array) => false false I also tested this in Julia 0.2.1 where it works as expected, i.e. no bug. Can you submit a bug report on https://github.com/JuliaLang/julia/issues?milestone=7&state=open Thanks! On Fri, 2014-07-18 at 08:57, Pontus Stenetorp <[email protected]> wrote: > Everyone, > > I recently took the introspection aspects of Julia for a spin and > tried to pick out the values of all the fields of a composite type > that were of a subtype of a certain type. What I observed puzzled me > and after some time staring at the code I constructed the following > minimal example that still exhibits the same odd behaviour. > > type Foo{T<:Real} > bar::Array{T,2} > qux::Bool > end > > foo = Foo(rand(2, 2), true) > > for name in names(foo) > @show name > @show fieldtype(foo, name) > @show issubtype(fieldtype(foo, name), Array) > end > @show issubtype(Array{Float64,2}, Array) > @show issubtype(fieldtype(foo, :bar), Array) > > If we run this code using the latest master, we observe: > > > julia foo.jl > name => :bar > fieldtype(foo,name) => Array{Float64,2} > issubtype(fieldtype(foo,name),Array) => false > name => :qux > fieldtype(foo,name) => Bool > issubtype(fieldtype(foo,name),Array) => false > issubtype(Array{Float64,2},Array) => true > issubtype(fieldtype(foo,:bar),Array) => true > > I really can not grasp why `issubtype` returns `false` for the field > `bar` in the loop, but not when evaluated with its type stand-alone as > on the last line. I am sure that I am missing something here and I > would very much appreciate if someone could tell me what aspect of > Julia introspection that I have yet to understand. > > Regards, > Pontus Stenetorp --
