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

Reply via email to