# @code\_warntype with StaticArrays

**URL:** https://discourse.julialang.org/t/code-warntype-with-staticarrays/81673
**Category:** New to Julia
**Created:** [May 25, 2022, 7:11pm UTC](https://discourse.julialang.org/t/code-warntype-with-staticarrays/81673 "2022-05-25T19:11:52Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![james3](https://avatars.discourse-cdn.com/v4/letter/j/b5e925/32.png) [@james3](https://discourse.julialang.org/u/james3)
#### Post date: [May 25, 2022, 7:11pm UTC](https://discourse.julialang.org/t/code-warntype-with-staticarrays/81673/1 "2022-05-25T19:11:52Z")

</div>

I am initializing a `MVector` and `MMatrix` from `StaticArrays` inside a function as follows

```julia
function test(v::Vector{T}) where{T<:Real}
    n = length(v)
    myvec = MVector{n, T}(undef)
    mymat = MMatrix{n, n, T}(undef)

...

end

```

If I do

```julia
v=[1.0, 2.0]
@code_warntype test(v)

```

I get output that begins

```julia
Static Parameters
  T = Float64
Arguments
  #self#::Core.Const(test)
  v::Vector{Float64}
Locals
  mymat::Any
  myvec::MArray{_A, Float64, 1} where _A<:Tuple
  n::Int64
Body::Any

```

What am I doing wrong when I initialize my vector and matrix? Thanks.

---

<div class="post-metadata">

### Author: ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)
#### Post date: [May 25, 2022, 7:23pm UTC](https://discourse.julialang.org/t/code-warntype-with-staticarrays/81673/2 "2022-05-25T19:23:44Z")

</div>

StaticArrays are type-inferred if the size is known at compile time, not runtime. In your case, `n` is only known at run-time, so the type can’t be inferred. Moreover, in the `MMatrix` constructor, you need to specify the fourth parameter, which is the length of the array `n^2`.
