From db2cc622b67bcc2c791e419737a8a4e1d82fdc33 Mon Sep 17 00:00:00 2001 From: nhz2 Date: Mon, 2 Feb 2026 01:20:48 -0500 Subject: [PATCH] In Julia 1.13 fieldoffset works with field names --- src/MutatePlainDataArray.jl | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/MutatePlainDataArray.jl b/src/MutatePlainDataArray.jl index 5ffaca2..56bfa23 100644 --- a/src/MutatePlainDataArray.jl +++ b/src/MutatePlainDataArray.jl @@ -23,23 +23,26 @@ function field_offset_type_impl(::Type{T}, ::Val{S}) where {T,S} if !isstructtype(T) error("$T is not struct type.") end - if S isa Symbol - fs = fieldnames(T) - findex = findfirst(==(S), fs) - if isnothing(findex) - if VERSION ≥ v"1.12" - throw(FieldError(T, S)) - else - error("Cannot find field $S in type $T.") + @static if VERSION ≥ v"1.13" + fieldoffset(T, S), fieldtype(T, S) + else + if S isa Symbol + fs = fieldnames(T) + findex = findfirst(==(S), fs) + if isnothing(findex) + if VERSION ≥ v"1.12" + throw(FieldError(T, S)) + else + error("Cannot find field $S in type $T.") + end end + elseif S isa Integer + findex = S + else + error("$S is not a symbol or an integer.") end - elseif S isa Integer - findex = S - else - error("$S is not a symbol or an integer.") + fieldoffset(T, findex), fieldtype(T, findex) end - - fieldoffset(T, findex), fieldtype(T, findex) end """