Julia v1.3.0 on OSX v10.15.4
a = Array[]
append!(a, "foo")
> ERROR: MethodError: Cannot `convert` an object of type Char to an object of type String
push!(a, "bar")
> 4-element Array{String,1}:
#undef
#undef
#undef
"bar"
https://github.com/JuliaLang/julia/blob/d6d5208d66be637543232bec4b0c79b2811ea1c6/base/array.jl#L986-L994
resize! happens before any setindex! is attempted.
Would that do what you expect?
append!(a, iter) = for i in iter; push!(a, i) end
Duplicate of https://github.com/JuliaLang/julia/issues/15868 and https://github.com/JuliaLang/julia/issues/7642, ref https://github.com/JuliaLang/julia/pull/7671.
Yes, this is annoying behaviour, but checking whether each element can convert is unacceptably slow.
Would that do what you expect?
append!(a, iter) = for i in iter; push!(a, i) end
Yes it would. I was mainly surprised that a failed operation grew the array, this behaviour was unexpected.
Duplicate of #15868 and #7642, ref #7671.
Yes, this is annoying behaviour, but checking whether each element can convert is unacceptably slow.
That's fair! I'm closing this issue in favour of #15868.
Most helpful comment
Duplicate of https://github.com/JuliaLang/julia/issues/15868 and https://github.com/JuliaLang/julia/issues/7642, ref https://github.com/JuliaLang/julia/pull/7671.
Yes, this is annoying behaviour, but checking whether each element can convert is unacceptably slow.