Skip to content

Commit c1e41aa

Browse files
committed
setindex! for non-isbits MArrays
Implement this for the sake of people using MArray in generic code, even though it's unlikely to be fast.
1 parent f330604 commit c1e41aa

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/MArray.jl

+1-3
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,7 @@ end
9494
if isbitstype(T)
9595
GC.@preserve v unsafe_store!(Base.unsafe_convert(Ptr{T}, pointer_from_objref(v)), convert(T, val), i)
9696
else
97-
# This one is unsafe (#27)
98-
# unsafe_store!(Base.unsafe_convert(Ptr{Ptr{Nothing}}, pointer_from_objref(v.data)), pointer_from_objref(val), i)
99-
error("setindex!() with non-isbitstype eltype is not supported by StaticArrays. Consider using SizedArray.")
97+
@inbounds v.data = setindex(v.data, val, i)
10098
end
10199

102100
return val

test/MArray.jl

+6-3
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,12 @@
142142
@test_throws BoundsError setindex!(mm, 4, -1)
143143
@test_throws BoundsError setindex!(mm, 4, 82)
144144

145-
# setindex with non-elbits type
146-
m = MArray{Tuple{2,2,2}, String}(undef)
147-
@test_throws ErrorException setindex!(m, "a", 1, 1, 1)
145+
# setindex with non-bits eltype
146+
m = fill(MMatrix{2,2, String}, "a")
147+
m[1,1] = "b"
148+
m[1,2] = "c"
149+
@test m == ["b" "c";
150+
"a" "a"]
148151
end
149152

150153
@testset "promotion" begin

0 commit comments

Comments
 (0)