diff --git a/src/structarray.jl b/src/structarray.jl index 496604e0..0d9792c3 100644 --- a/src/structarray.jl +++ b/src/structarray.jl @@ -505,7 +505,7 @@ Base.@pure cst(::Type{SA}) where {SA} = combine_style_types(array_types(SA).para BroadcastStyle(::Type{SA}) where {SA<:StructArray} = StructArrayStyle{typeof(cst(SA)), ndims(SA)}() -function Base.similar(bc::Broadcasted{StructArrayStyle{S, N}}, ::Type{ElType}) where {S<:DefaultArrayStyle, N, ElType} +function Base.similar(bc::Broadcasted{StructArrayStyle{S, N}}, ::Type{ElType}) where {S<:Union{DefaultArrayStyle,StructArrayStyle}, N, ElType} ContainerType = isnonemptystructtype(ElType) ? StructArray{ElType} : Array{ElType} return similar(ContainerType, axes(bc)) end diff --git a/test/runtests.jl b/test/runtests.jl index 347438d9..d9040542 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1142,6 +1142,9 @@ Base.similar(bc::Broadcast.Broadcasted{Broadcast.ArrayStyle{MyArray}}, ::Type{El # issue #189 v = StructArray([(a="s1",), (a="s2",)]) @test @inferred(broadcast(el -> el.a, v)) == ["s1", "s2"] + + @test identity.(StructArray(x=StructArray(a=1:3)))::StructArray == [(x=(a=1,),), (x=(a=2,),), (x=(a=3,),)] + @test (x -> x.x.a).(StructArray(x=StructArray(a=1:3))) == [1, 2, 3] end @testset "map" begin