# Getfield with Measurements -\> access to undefined reference

**URL:** <https://discourse.julialang.org/t/getfield-with-measurements-access-to-undefined-reference/37159>\
**Category:** Data\
**Created:** [April 7, 2020, 11:32am UTC](https://discourse.julialang.org/t/getfield-with-measurements-access-to-undefined-reference/37159 "2020-04-07T11:32:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MartinOtter](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@MartinOtter](https://discourse.julialang.org/u/MartinOtter)\
**Post date:** [April 7, 2020, 11:32am UTC](https://discourse.julialang.org/t/getfield-with-measurements-access-to-undefined-reference/37159/1 "2020-04-07T11:32:42Z")

</div>

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:

```julia
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).

---

<div class="post-metadata">

**Author:** ![MartinOtter](https://avatars.discourse-cdn.com/v4/letter/m/87869e/32.png) [@MartinOtter](https://discourse.julialang.org/u/MartinOtter)\
**Post date:** [April 7, 2020, 1:24pm UTC](https://discourse.julialang.org/t/getfield-with-measurements-access-to-undefined-reference/37159/2 "2020-04-07T13:24:46Z")

</div>

Have found a solution: I need to inquire only the type of a field, and the call

```julia
vtype = fieldtype(typeof(obj), :L)

```

gives no error.
