Skip to content

Commit a5b24b6

Browse files
author
Pietro Vertechi
authored
Ensure inbounds work on setindex (#75)
1 parent 4b5077d commit a5b24b6

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/structarray.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Base.size(s::StructArray{<:Any, <:Any, <:EmptyTup}) = (0,)
116116
Base.axes(s::StructArray) = axes(fieldarrays(s)[1])
117117
Base.axes(s::StructArray{<:Any, <:Any, <:EmptyTup}) = (1:0,)
118118

119-
@generated function Base.getindex(x::StructArray{T, N, C}, I::Int...) where {T, N, C}
119+
Base.@propagate_inbounds @generated function Base.getindex(x::StructArray{T, N, C}, I::Int...) where {T, N, C}
120120
args = [:(getfield(cols, $i)[I...]) for i in 1:fieldcount(C)]
121121
return quote
122122
cols = fieldarrays(x)
@@ -129,9 +129,9 @@ function Base.view(s::StructArray{T, N, C}, I...) where {T, N, C}
129129
StructArray{T}(map(v -> view(v, I...), fieldarrays(s)))
130130
end
131131

132-
function Base.setindex!(s::StructArray, vals, I::Int...)
132+
Base.@propagate_inbounds function Base.setindex!(s::StructArray, vals, I::Int...)
133133
@boundscheck checkbounds(s, I...)
134-
@inbounds foreachfield((col, val) -> (col[I...] = val), s, vals)
134+
foreachfield((col, val) -> (@inbounds col[I...] = val), s, vals)
135135
s
136136
end
137137

0 commit comments

Comments
 (0)