Skip to content

Commit 03af483

Browse files
authored
In Julia 1.13 fieldoffset works with field names (#11)
1 parent 46598df commit 03af483

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

src/MutatePlainDataArray.jl

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,23 +23,26 @@ function field_offset_type_impl(::Type{T}, ::Val{S}) where {T,S}
2323
if !isstructtype(T)
2424
error("$T is not struct type.")
2525
end
26-
if S isa Symbol
27-
fs = fieldnames(T)
28-
findex = findfirst(==(S), fs)
29-
if isnothing(findex)
30-
if VERSION v"1.12"
31-
throw(FieldError(T, S))
32-
else
33-
error("Cannot find field $S in type $T.")
26+
@static if VERSION v"1.13"
27+
fieldoffset(T, S), fieldtype(T, S)
28+
else
29+
if S isa Symbol
30+
fs = fieldnames(T)
31+
findex = findfirst(==(S), fs)
32+
if isnothing(findex)
33+
if VERSION v"1.12"
34+
throw(FieldError(T, S))
35+
else
36+
error("Cannot find field $S in type $T.")
37+
end
3438
end
39+
elseif S isa Integer
40+
findex = S
41+
else
42+
error("$S is not a symbol or an integer.")
3543
end
36-
elseif S isa Integer
37-
findex = S
38-
else
39-
error("$S is not a symbol or an integer.")
44+
fieldoffset(T, findex), fieldtype(T, findex)
4045
end
41-
42-
fieldoffset(T, findex), fieldtype(T, findex)
4346
end
4447

4548
"""

0 commit comments

Comments
 (0)