Invalid redefinition of constant in comprehensions


#1

I am running the following code from the following section in Julia manual: https://docs.julialang.org/en/latest/manual/arrays/#Comprehensions-1:

x = rand(8)
[ 0.25*x[i-1] + 0.5*x[i] + 0.25*x[i+1] for i=2:length(x)-1 ]
Float32[ 0.25*x[i-1] + 0.5*x[i] + 0.25*x[i+1] for i=2:length(x)-1 ]

all works fine.
Now I define a function:

s4() = 0

and running the above code fails. More specifically the last expression returns:

julia> Float32[ 0.25*x[i-1] + 0.5*x[i] + 0.25*x[i+1] for i=2:length(x)-1 ]
ERROR: invalid redefinition of constant #s4
Stacktrace:
 [1] anonymous at .\<missing>:?

More specifically the following error happens when:

  • function of name s1, s2, s3 or s4 is defined;
  • a type is prepended to the comprehension.

Is it a bug or I am missing someting trivial?


#2

It’s another funny bug similar to https://github.com/JuliaLang/julia/issues/23809