diff --git a/src/broadcast.jl b/src/broadcast.jl index 710b7642b..b5a69b634 100644 --- a/src/broadcast.jl +++ b/src/broadcast.jl @@ -108,21 +108,17 @@ first_statictype() = error("unresolved dest type") @inline function _broadcast(f, sz::Size{newsize}, s::Tuple{Vararg{Size}}, a...) where newsize first_staticarray = first_statictype(a...) + if prod(newsize) == 0 + # Use inference to get eltype in empty case (see also comments in _map) + eltys = Tuple{map(eltype, a)...} + T = Core.Compiler.return_type(f, eltys) + @inbounds return similar_type(first_staticarray, T, Size(newsize))() + end elements = __broadcast(f, sz, s, a...) @inbounds return similar_type(first_staticarray, eltype(elements), Size(newsize))(elements) end @generated function __broadcast(f, ::Size{newsize}, s::Tuple{Vararg{Size}}, a...) where newsize - if prod(newsize) == 0 - # Use inference to get eltype in empty case (see also comments in _map) - eltys = [:(eltype(a[$i])) for i ∈ 1:length(a)] - return quote - @_inline_meta - T = Core.Compiler.return_type(f, Tuple{$(eltys...)}) - @inbounds return similar_type($first_staticarray, T, Size(newsize))() - end - end - sizes = [sz.parameters[1] for sz ∈ s.parameters] indices = CartesianIndices(newsize) exprs = similar(indices, Expr)