I’m trying to make a structure that contains a static array. Here’s a minimal example:
using StaticArrays
mutable struct Foo{N<:Integer,T}
v :: MVector{N,T}
end
function Foo(x::N, y::T) where {N<:Integer,T}
w = MVector{x, typeof(y)}(undef)
Foo(w)
end
In the outer constructor, the 2nd argument is only used to determine the type of the entries in the array. This seems like a kluge, and I’d be grateful to hear about a better approach. But this one, inelegant as it is, ought to work and does work for “Vector”. But it fails with “MVector”. I get a method error, yet the signature of the unmatched method looks as though it ought to match the first of the listed candidates. Here’s the error message:
julia> Foo(3, 1.0)
ERROR: MethodError: no method matching Foo(::MArray{Tuple{3},Float64,1,3})
Closest candidates are:
Foo(::MArray{Tuple{N},T,1,N}) where {N<:Integer, T} at /Users/rogers/src/MatrixCoalescent/src/foo.jl:4
Foo(::N, ::T) where {N<:Integer, T} at /Users/rogers/src/MatrixCoalescent/src/foo.jl:8
Stacktrace:
[1] Foo(::Int64, ::Float64) at /Users/rogers/src/MatrixCoalescent/src/foo.jl:9
[2] top-level scope at REPL[2]:1