diff --git a/base/broadcast.jl b/base/broadcast.jl index 1a4c50aa785378..867acbd5ca6ed9 100644 --- a/base/broadcast.jl +++ b/base/broadcast.jl @@ -241,6 +241,9 @@ end # broadcast methods that dispatch on the type found by inference function _broadcast_t(f, ::Type{Any}, shape, iter, As...) + if isempty(iter) + return similar(Array{Any}, shape) + end nargs = length(As) keeps, Idefaults = map_newindexer(shape, As) st = start(iter) @@ -272,14 +275,16 @@ ziptype(A, B) = Zip2{Tuple{eltype(A)},Tuple{eltype(B)}} # broadcast methods that dispatch on the type of the final container @inline function broadcast_c(f, ::Type{Array}, As...) - S = _default_eltype(Generator{ziptype(As...),ftype(f, As...)}) + T = _default_eltype(Generator{ziptype(As...),ftype(f, As...)}) shape = broadcast_indices(As...) iter = CartesianRange(shape) + if isleaftype(T) + return _broadcast_t(f, T, shape, iter, As...) + end if isempty(iter) - return similar(Array{S}, shape) + return similar(Array{T}, shape) end - T = isleaftype(S) ? S : Any - return _broadcast_t(f, T, shape, iter, As...) + return _broadcast_t(f, Any, shape, iter, As...) end function broadcast_c(f, ::Type{Tuple}, As...) shape = broadcast_indices(As...)