Reading Arrays of composite struct #2169

Closed
Keno opened this Issue Feb 1, 2013 · 6 comments

Projects

None yet

3 participants

@Keno
Member
Keno commented Feb 1, 2013

I think this should work:

julia> cd("dir")

julia> type Foo{T}
       a::T
       end

julia> import Base.read

julia> read{T}(io::IO,::Type{Foo{T}}) = Foo(read(io,a))

julia> fd=open("file");

julia> read(fd,Array(Foo{Float64},1))
no method read(IOStream,TypeVar)
 in read at io.jl:108
 in read at io.jl:369

changing

function read{T}(s::IO, a::Array{T})
    for i = 1:length(a)
        a[i] = read(s, T)
    end
    return a
end

to

function read{T}(s::IO, a::Array{T})
    for i = 1:length(a)
        a[i] = read(s, eltype(a))
    end
    return a
end

works, but it doesn't seem like that should be necessary. Maybe some kind of type inference issue? @JeffBezanson

@JeffBezanson
Member

That read definition is missing a {T}

@Keno
Member
Keno commented Feb 1, 2013

You're right of course, but that was just a typo when opening the issue (that's what I get for simplifying things without testing them). I updated the issue text and verified that it actually shows the issue.

@vtjnash
Member
vtjnash commented Feb 1, 2013

you have a typo here: read(fd,Array(Foo{Float64},1))

it should be { }, otherwise the compile-time type of that parameter is a bit wonky (e.g. it is T, a TypeVar)

@Keno
Member
Keno commented Feb 1, 2013

The point was that want to be able to do this:

a=Array(Foo{Float64},1024)
read(fd,a) #read me 1024 entries into a

It's documented to work that way, but it doesn't.

@vtjnash
Member
vtjnash commented Feb 1, 2013

Ah, although the point is still the same. the compile-time parameter (apparently) is getting left as a TypeVar. Maybe this is a compiler bug then? perhaps TypeVars should be special-cased as unresolved references (like a global variable) in the code generation step?

@JeffBezanson JeffBezanson was assigned Feb 3, 2013
@JeffBezanson JeffBezanson added a commit that closed this issue Feb 3, 2013
@JeffBezanson JeffBezanson fix #2169 beb277b
@Keno
Member
Keno commented Feb 3, 2013

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment