Strange re-typing of arrays of numbers

This happened twice now in a short time. Compare:

Should there be a warning in the docs? Like, for example, here:

https://docs.julialang.org/en/v1/manual/arrays/#man-array-literals

Something along the lines of:

"Remember, promotion to a common type may also change the type of nested arrays:

julia> arr = [Int[1,2],[]]
3-element Array{Array{Any,1},1}:
 [1, 2]
 []

julia> arr[1]
2-element Array{Any,1}:
 1
 2

To prevent this, declare an abstract type for the containing array:

julia> arr2 = Any[[1,2],[]]
3-element Array{Any,1}:
 [1, 2]
 Any[]

julia> arr2[1]
2-element Array{Int64,1}:
 1
 2

"

1 Like