Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow mutation of non-isbits eltypes #1150

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/MArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ end
else
# This one is unsafe (#27)
# unsafe_store!(Base.unsafe_convert(Ptr{Ptr{Nothing}}, pointer_from_objref(v.data)), pointer_from_objref(val), i)
error("setindex!() with non-isbitstype eltype is not supported by StaticArrays. Consider using SizedArray.")
# error("setindex!() with non-isbitstype eltype is not supported by StaticArrays. Consider using SizedArray.")
setfield!(v, :data, Base.setindex(getfield(v, :data), convert(eltype(v), val), i))
end

return v
end

Expand Down
6 changes: 4 additions & 2 deletions test/MArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,10 @@
@test_throws BoundsError setindex!(mm, 4, 82)

# setindex with non-elbits type
m = MArray{Tuple{2,2,2}, String}(undef)
@test_throws ErrorException setindex!(m, "a", 1, 1, 1)
m = MArray{Tuple{2,2,2}, String}(ntuple(_ -> "b", 2^3))
@test setindex!(m, "a", 1, 1, 1) == MArray{Tuple{2,2,2}, String}(ntuple(i -> i == 1 ? "a" : "b", 2^3))
@test m[1,1,1] == "a"
@test m[1,1,2] == "b"
end

@testset "promotion" begin
Expand Down