Outer constructors with a field of static vector

Dear all,

Can you help me to clarify some point?

Suppose, I have two composite types, one of them is parametric. They look rather similar.

using StaticArrays
struct test1
t::SVector{5,AbstractFloat}
end

struct test2{T<:AbstractFloat}
t::SVector{5,T}
end

The constructor test1 can convert a vector to a static vector while making the object.

test1([1.0:5.0…])
test1(AbstractFloat[1.0, 2.0, 3.0, 4.0, 5.0])

test2 can’t

test2([1.0:5.0…])
ERROR: MethodError: no method matching test2(::Array{Float64,1})
Closest candidates are:
test2(::SArray{Tuple{5},T<:AbstractFloat,1,5}) where T<:AbstractFloat at REPL[4]:2.

What is the cause of this difference?

The default constructors generated seem different.

julia> methods(test1)
# 2 methods for type constructor:
[1] test1(t::SArray{Tuple{5},AbstractFloat,1,5}) in Main at REPL[6]:2
[2] test1(t) in Main at REPL[6]:2

julia> methods(test2)
# 1 method for type constructor:
[1] (::Type{test2})(t::SArray{Tuple{5},T,1,5}) where T<:AbstractFloat in Main at REPL[7]:2

test1 has an extra method that can convert any type to an SArray, while test2 doesn’t. You can add your own though:

julia> test2(v::AbstractVector{T}) where {T<:AbstractFloat} = test2{T}(SVector{5,T}(v))
test2

julia> test2([1.0:5.0...])
test2{Float64}([1.0, 2.0, 3.0, 4.0, 5.0])

Thank you so much!