# FlexUnits & Structs

**URL:** <https://discourse.julialang.org/t/flexunits-structs/142738>\
**Category:** General Usage\
**Created:** [November 3, 2026, 4:53pm UTC](https://discourse.julialang.org/t/flexunits-structs/142738 "2026-11-03T16:53:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jake](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jake/32/46007_2.png) [@Jake](https://discourse.julialang.org/u/Jake)\
**Post date:** [November 3, 2026, 4:53pm UTC](https://discourse.julialang.org/t/flexunits-structs/142738/1 "2026-11-03T16:53:29Z")

</div>

In creating a struct with units I don’t have a problem if each field of the struct has units. I am running into an error when not all the fields have units. Can someone show me where I am going wrong.

```julia-auto
# Test unit structures
using FlexUnits, .UnitRegistry
import FlexUnits: QuantFieldVector, DimsMod

mutable struct Foo{T} <: QuantFieldVector{2,T}
    num::Integer
    leng::Quantity{T, D"m"}
end

num = 2
leng = 2.2u"m"
F = Foo(; num, leng)
ERROR: MethodError: no method matching Foo(; num::Int64, leng::Quantity{Float64, StaticDims{m}})
This method does not support all of the given keyword arguments (and may not support any).

Closest candidates are:
  Foo(::Integer, ::Quantity{T, StaticDims{m}}) where T got unsupported keyword arguments "num", "leng"
   @ Main REPL[5]:2
  (::Type{FA})(::Tuple) where FA<:StaticArraysCore.FieldArray got unsupported keyword arguments "num", "leng"
   @ StaticArrays C:\Users\jakez\.julia\packages\StaticArrays\SXG7G\src\FieldArray.jl:2
  (::Type{SA})(::Base.Generator) where SA<:StaticArraysCore.StaticArray got unsupported keyword arguments "num", "leng"
   @ StaticArrays C:\Users\jakez\.julia\packages\StaticArrays\SXG7G\src\SArray.jl:57
  ...

Stacktrace:
 [1] top-level scope
   @ REPL[8]:1

ERROR: MethodError: no method matching Foo(; num::Int64, leng::Quantity{Float64, StaticDims{m}})
This method does not support all of the given keyword arguments (and may not support any).

Closest candidates are:
  Foo(::Integer, ::Quantity{T, StaticDims{m}}) where T got unsupported keyword arguments "num", "leng"
   @ Main c:\data\st\Julia\WinderCurves\examples\addseries\test.jl:44
  (::Type{FA})(::Tuple) where FA<:StaticArraysCore.FieldArray got unsupported keyword arguments "num", "leng"
   @ StaticArrays C:\Users\jakez\.julia\packages\StaticArrays\SXG7G\src\FieldArray.jl:2
  (::Type{SA})(::Base.Generator) where SA<:StaticArraysCore.StaticArray got unsupported keyword arguments "num", "leng"
   @ StaticArrays C:\Users\jakez\.julia\packages\StaticArrays\SXG7G\src\SArray.jl:57
  ...

Stacktrace:
 [1] top-level scope
   @ c:\data\st\Julia\WinderCurves\examples\addseries\test.jl:50

julia> 

```

---

<div class="post-metadata">

**Author:** ![JonasWickman](https://avatars.discourse-cdn.com/v4/letter/j/9de0a6/32.png) [@JonasWickman](https://discourse.julialang.org/u/JonasWickman)\
**Post date:** [November 3, 2026, 5:44pm UTC](https://discourse.julialang.org/t/flexunits-structs/142738/2 "2026-11-03T17:44:17Z")

</div>

I think perhaps it’s just an errant semicolon. Try

```julia-auto
F = Foo(num, leng)

```
