# Strange error message when trying to initialise field of type SVector

**URL:** <https://discourse.julialang.org/t/strange-error-message-when-trying-to-initialise-field-of-type-svector/2222>\
**Category:** General Usage\
**Created:** [February 21, 2017, 6:52pm UTC](https://discourse.julialang.org/t/strange-error-message-when-trying-to-initialise-field-of-type-svector/2222 "2017-02-21T18:52:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![krcools](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/krcools/32/10212_2.png) [@krcools](https://discourse.julialang.org/u/krcools)\
**Post date:** [February 21, 2017, 6:52pm UTC](https://discourse.julialang.org/t/strange-error-message-when-trying-to-initialise-field-of-type-svector/2222/1 "2017-02-21T18:52:30Z")

</div>

I was hoping someone could talk me through why this throws:

```julia
using StaticArrays

type Polly{N,T}
    data::SVector{N,T}
end

p = Polly{2,Float64}((1.0, 0.0))

```

and adds insult to injury with this curious error message:

```julia
LoadError: No precise constructor found. Length of input was 2 while length of StaticArrays.SVector{2,Float64} is 2.

```

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [February 21, 2017, 8:26pm UTC](https://discourse.julialang.org/t/strange-error-message-when-trying-to-initialise-field-of-type-svector/2222/2 "2017-02-21T20:26:25Z")

</div>

> [@krcools](#):
>
> hile length of StaticArrays.SVector{2,Float64} is 2.

You need

```julia
julia> Polly{2,Float64}(SVector(1.0, 0.0))

```

but actually

```julia
julia> Polly(SVector(1.0, 0.0))
Polly{2,Float64}([1.0,0.0])

```

works out the type (“infers the type”) automatically.

You probably want an outer constructor like

```julia
julia> Polly(t::Tuple) = Polly(SVector(t))
Polly{N,T}

```

to be able to just do

```julia
julia> Polly((2,3))
Polly{2,Int64}([2,3])

```

and then you can do

```julia
julia> Polly(t...) = Polly(t)

```

to have

```julia

julia> Polly(2, 3)
Polly{2,Int64}([2,3])

```

---

<div class="post-metadata">

**Author:** ![andyferris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andyferris/32/235_2.png) [@andyferris](https://discourse.julialang.org/u/andyferris)\
**Post date:** [February 21, 2017, 10:30pm UTC](https://discourse.julialang.org/t/strange-error-message-when-trying-to-initialise-field-of-type-svector/2222/3 "2017-02-21T22:30:13Z")

</div>

The problem is a missing `convert` method in `StaticArrays`, apparently:

```julia
julia> using StaticArrays

julia> convert(SVector{2,Float64}, (1.0, 2.0))
ERROR: No precise constructor found. Length of input was 2 while length of StaticArrays.SVector{2,Float64} is 2.
 in convert(::Type{StaticArrays.SVector{2,Float64}}, ::Tuple{Float64,Float64}) at /home/ferris/.julia/v0.5/StaticArrays/src/core.jl:39

```

The (abstract type) constructors in `StaticArrays` are a mess (but I honestly thought this one worked… oh well). I was hoping to clear this up in Julia v0.6 because my previous attempts at getting a sensible set of constructors ran into the subtyping inconsistencies that Jeff Bezanson has recently fixed.

@krcools - so I can track this, could I get you to file an issue at [https://github.com/JuliaArrays/StaticArrays.jl](https://github.com/JuliaArrays/StaticArrays.jl) please? I also recommend the suggestions of @dpsanders to make your life easy. Nice constructors can make working with your types a breeze, but you often need several definitions to achieve a good/well rounded API.

---

<div class="post-metadata">

**Author:** ![krcools](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/krcools/32/10212_2.png) [@krcools](https://discourse.julialang.org/u/krcools)\
**Post date:** [February 22, 2017, 9:52am UTC](https://discourse.julialang.org/t/strange-error-message-when-trying-to-initialise-field-of-type-svector/2222/4 "2017-02-22T09:52:53Z")

</div>

Thank you both. @andyferris, I opened an issue in the project repo as requested.

I actually had a lot of the infrastructure @dpsanders refers to in place. The errors described here resulted upon migrating from `FixedSizeArrays` to `StaticArrays`. To be honest, I’m not a big fan of

```julia
Polly(t...) = Polly(t)

```

This creates an annoying corner case when you try to store a single `SVector` inside of another `SVector` (which I seem to do a lot given how many times I had to struggle with this case…)

---

<div class="post-metadata">

**Author:** ![andyferris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andyferris/32/235_2.png) [@andyferris](https://discourse.julialang.org/u/andyferris)\
**Post date:** [February 23, 2017, 7:58am UTC](https://discourse.julialang.org/t/strange-error-message-when-trying-to-initialise-field-of-type-svector/2222/5 "2017-02-23T07:58:41Z")

</div>

Yes, the one-element constructor is definitely rather tricky.

A single `SVector` inside a `SVector` could be even worse because of the ways constructors interact with `convert`.
