Skip to content

Possibly wrong TypeVar serialization with new typesystem #20324

@amitmurthy

Description

@amitmurthy
julia> abstract AbsFoo

julia> type Foo <: AbsFoo
           x
       end

julia> type Bar{T<:AbsFoo}
           x::T
       end

julia> x = Bar[Bar(Foo(1)) for i in 1:2]
2-element Array{Bar,1}:
 Bar{Foo}(Foo(1))
 Bar{Foo}(Foo(1))

julia> io=IOBuffer();

julia> serialize(io, x);

julia> seekstart(io);

julia> deserialize(io)
ERROR: MethodError: Cannot `convert` an object of type Bar{Foo} to an object of type Bar{T<:AbsFoo} where T<:AbsFoo
This may have arisen from a call to the constructor Bar{T<:AbsFoo} where T<:AbsFoo(...),
since type constructors fall back to convert methods.
Stacktrace:
 [1] setindex!(::Array{Bar{T<:AbsFoo} where T<:AbsFoo,1}, ::Bar{Foo}, ::Int64) at ./array.jl:489
 [2] deserialize_array(::SerializationState{Base.AbstractIOBuffer{Array{UInt8,1}}}) at ./serialize.jl:727
 [3] handle_deserialize(::SerializationState{Base.AbstractIOBuffer{Array{UInt8,1}}}, ::Int32) at ./serialize.jl:578
 [4] deserialize(::SerializationState{Base.AbstractIOBuffer{Array{UInt8,1}}}) at ./serialize.jl:550
 [5] deserialize(::Base.AbstractIOBuffer{Array{UInt8,1}}) at ./serialize.jl:547

Metadata

Metadata

Assignees

Labels

bugIndicates an unexpected problem or unintended behaviorparallelismParallel or distributed computationtypes and dispatchTypes, subtyping and method dispatch

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions