-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Description
I accidentally stumbled on the following:
julia> v = Union{Vector{Int}, Nothing}[Vector{Int}[] for _ in 1:3]This returns a Vector{Union{Vector{Int}, Nothing}} but, really, I think it should error. The issue is that the elements in [Vector{Int}[] for _ in 1:3] are not Vector{Int} but Vector{Vector{Int}}, so we have scenario of the kind Union{A, B}[c::C for c in ...] with C not a subtype of A or B.
The reason this works is that each of the Vector{Int}[] elements are passed on to the conversion machinery. In particular, as pointed out by @thofma on Slack, this is probably passed to one of these methods:
julia> convert(Vector{Int}, Vector{Int}[]) # Int64[]
julia> Vector{Int}(Vector{Int}[]) # Int64[]It's hard to see where this would be desirable though. Additionally, the conversion only works if the to-be-converted-array is empty. That is, the following fails:
julia> convert(Vector{Int}, Vector{Int}[[1,2,3],[4,5]])
julia> Vector{Int}(Vector{Int}[[1,2,3],[4,5]])It seems strange and error-prone to have conversion methods that only work for empty input.