Skip to content

setindex! not performing type conversions #216

@tobiaslcmueller

Description

@tobiaslcmueller

setindex! does not perform type conversion and therefore does not behave as expected from Base.setindex!
In particular

a = zeros(ComplexF64, 2);
setindex!(a, 5.0, 2)

works as expected, while the corresponding StructArray version

a = StructArray(zeros(ComplexF64, 2));
setindex!(a, 5.0, 2)`

errors with

ERROR: type Float64 has no field re
Stacktrace:
[1] component(x::Float64, i::Symbol)
@ StructArrays ~/.julia/packages/StructArrays/0C03x/src/interface.jl:10
[2] macro expansion
@ ~/.julia/packages/StructArrays/0C03x/src/utils.jl:82 [inlined]
[3] foreachfield_gen(::StructVector{ComplexF64, NamedTuple{(:re, :im), Tuple{Vector{Float64}, Vector{Float64}}}, Int64}, ::StructArrays.var"#39#40"{Int64}, ::StructVector{ComplexF64, NamedTuple{(:re, :im), Tuple{Vector{Float64}, Vector{Float64}}}, Int64}, ::Float64)
@ StructArrays ~/.julia/packages/StructArrays/0C03x/src/utils.jl:82
[4] foreachfield(f::StructArrays.var"#39#40"{Int64}, x::StructVector{ComplexF64, NamedTuple{(:re, :im), Tuple{Vector{Float64}, Vector{Float64}}}, Int64}, xs::Float64)
@ StructArrays ~/.julia/packages/StructArrays/0C03x/src/utils.jl:85
[5] setindex!(s::StructVector{ComplexF64, NamedTuple{(:re, :im), Tuple{Vector{Float64}, Vector{Float64}}}, Int64}, vals::Float64, I::Int64)
@ StructArrays ~/.julia/packages/StructArrays/0C03x/src/structarray.jl:361

Not sure, if that is intended behavior, but it prevents StructArrays behaving as a drop-in replacement for Base Arrays.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions