Is this a bug? relevant for > 0.4.6


the following code behaves unexpectedly:

if 1>0
beta = 0.5
print(“1. beta=”,beta,“\n”)

for i1=1:2

print("2. beta = ", beta, “\n”)
print("3. beta = ", beta, “\n”)

It produces:

  1. beta=beta
  2. beta = beta
  3. beta = 0.5
    WARNING: imported binding for beta overwritten in module Main

while if you comment out the for cycle, you always get the expected beta = 0.5.
Please note that the result shown above is only seen if the kerner runs for
the first time over the code.

Version 0.4.6 behaves, in contrast, as expected (we get 0.5).

Can anybody comment on it?

Thanks for any help
Ruda and Martin

1 Like

I can also produce the same result in the following way:

julia> methods(beta)
# 4 methods for generic function "beta":
beta(x::Number, w::Number) at special/gamma.jl:492
beta{T1<:Number,T2<:Number}(x::T1, y::AbstractArray{T2,N<:Any}) at operators.jl:562
beta{T1<:Number,T2<:Number}(x::AbstractArray{T1,N<:Any}, y::T2) at operators.jl:563
beta{T1<:Number,T2<:Number}(x::AbstractArray{T1,N<:Any}, y::AbstractArray{T2,N<:Any}) at operators.jl:564

julia> beta = 0.5
WARNING: imported binding for beta overwritten in module Main

Not calling methods(beta) does not produce the warning.

I’m guessing the for statement triggers compilation of the entire code-block, whereas a block without a loop is compiled and executed line-by-line. So the situation is similar to:

function foo()
   @eval Main beta = 0.5
   print("Main.beta = ", Main.beta,"\n")

This will output the warning, followed by “Main.beta = beta”, which is expected and documented behavior, because changing beta does not trigger re-compilation of the function. The case of the REPL is different, though…

Defining a variable before it has been used in any way does not trigger a warning (or method extension error) because doing so would cause new exports from packages that clash with variable names in the code using the packages to break existing code.

julia> beta = 3

julia> workspace()

julia> beta
bbeta (generic function with 4 methods)

julia> beta = 3
WARNING: imported binding for beta overwritten in module Main

julia> workspace()

julia> beta(x::Int) = 3
beta (generic function with 1 method)

julia> workspace()

julia> beta
beta (generic function with 4 methods)

julia> beta(x::Int) = 3
ERROR: error in method definition: function Math.beta must be explicitly imported to be extended

I don’t think the point of the original post was to discuss the warning, but rather the fact that the assignment beta = 0.5 inside the if-statement at the REPL does not take effect immediately.

Yes, the warning is not the issue.
Primarily, we did not expect ‘beta=beta’ anywhere in the output.

So can anybody tell if what we see is a bug?
The behaviour, i.e., seeing beta=beta anywhere, is very


Are you aware that there is (was) a function called beta, which is what you are seeing?

Sounds like a bug to me, or at least it’s worth filing an issue. I don’t see why adding these two lines:

for i1=1:2

should change anything to the behavior of the program.

Yes, we know there exists the beta function.
Still, this fact should not, we believe, cause such behaviour.


Thanks for the opinion.
I have expected the developers read this forum, too.
I will file an issue unless somebody turns up here soon to argue it is ok.