The following code:
Base.@kwdef mutable struct SysState{P}
acc::Float64 = 0
"vector of particle positions in x [m]"
X::MVector{P, Float64} = zeros(P)
end
gives the warning:
`KiteUtils.P` is not defined
I think this is a bug, but the issue I created was closed: Invalid warning about type parameter · Issue #412 · aviatesk/JETLS.jl · GitHub
I don’t understand why. Is there a bug in the Base.@kwdef macro?
It looks like that:
julia> ex = @macroexpand Base.@kwdef mutable struct SysState{P}
acc::Float64 = 0
"vector of particle positions in x [m]"
X::Vector{P} = zeros(P)
end
quote
#= util.jl:630 =#
begin
$(Expr(:meta, :doc))
mutable struct SysState{P}
#= REPL[4]:2 =#
acc::Float64
#= REPL[4]:3 =#
"vector of particle positions in x [m]"
X::Vector{P}
end
end
#= util.jl:631 =#
begin
function SysState(; acc = 0, X = zeros(P))
#= REPL[4]:1 =#
SysState(acc, X)
end
function SysState{P}(; acc = 0, X = zeros(P)) where P
#= REPL[4]:1 =#
SysState{P}(acc, X)
end
end
end
Any comments?
I think I get the warning, because SysState() is not defined. But shouldn’t it be allowed to define a type that requires a type parameter?