When the following lines are run twice, the error invalid redefinition of constant X
is thrown. The code is rather random, but it is the most minimal example I could come up with without removing the problem. In particular, foo
does neither use A
nor X
but is essential.
abstract type A end
struct B <: A
r
end
const X = Vector{<:A}
function foo(b::B)
r = b.r
i = 1
for j in 1:length(r)
while r[j] > 0 && i<10
i+=1
end
end
end
Using the line X = Vector{T} where {T<:A}
works fine instead, even though Vector{<:A} == Vector{T} where {T<:A}
returns true
.
Does anyone know what might be going on? This initially caused me to use @isdefined
each time, but this seems unintended.