Redefining a struct with an identical definition does not lead to an ERROR: LoadError: invalid redefinition of constant
error:
mutable struct LFKernel
A0::Array{Float64, 2}
end
mutable struct LFKernel
A0::Array{Float64, 2}
end
Is it supposed to? After reorganizing some code, I found I had duplicate definitions in different files.
It also appears this can be used to trick the language into keeping the default constructor while also providing an inner constructor:
mutable struct LFKernel
A0::Array{Float64, 2}
function LFKernel(a::Int, b::Int)
return new(zeros(a, b))
end
end
mutable struct LFKernel
A0::Array{Float64, 2}
end
LFKernel(2, 3) # no error
LFKernel(zeros(2, 3)) # also no error
This could potentially lead to confusion about what constructors a type has by looking at the source code when the definitions are in different files.