In this test model, an unexpected error is raised from getfield(…) when applied on an uninitialized struct on a field of type Measurements, and I do not find the reason:
module Test_getfield
using Measurements
mutable struct Values{StateType}
L::StateType
function Values{StateType}(;L=1.0) where {StateType}
obj = new()
vfield = getfield(obj,:L)
setfield!(obj, :L, L)
return obj
end
end
val1 = Values{Float64}()
@show val1
val2 = Values{Measurement{Float64}}(L=1.0±0.1)
@show val2
end
The constructor Values(…) first constructs an uninitialized instance via obj = new()
. If getfield
is called afterwards on a type such as Float64, everything is fine. If, however, the field is of type Measurements, then an error access to undefined reference is raised. Could someone give advice, how to fix this.
(Of course the code fragment above makes not much sense, because the call to getfield(…) has no effect; it is just used to demonstrate the issue).