# Is this a bug? relevant for \> 0.4.6

**URL:** <https://discourse.julialang.org/t/is-this-a-bug-relevant-for-0-4-6/4030>\
**Category:** General Usage\
**Created:** [June 1, 2017, 10:55am UTC](https://discourse.julialang.org/t/is-this-a-bug-relevant-for-0-4-6/4030 "2017-06-01T10:55:54Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rudolf\_Sykora](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@Rudolf\_Sykora](https://discourse.julialang.org/u/Rudolf_Sykora)\
**Post date:** [June 1, 2017, 10:55am UTC](https://discourse.julialang.org/t/is-this-a-bug-relevant-for-0-4-6/4030/1 "2017-06-01T10:55:54Z")

</div>

Hello,

the following code behaves unexpectedly:

* * *

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

for i1=1:2  
end

## print("2. beta = ", beta, “\n”) end 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

---

<div class="post-metadata">

**Author:** ![mzaffalon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mzaffalon/32/214168_2.png) [@mzaffalon](https://discourse.julialang.org/u/mzaffalon)\
**Post date:** [June 1, 2017, 11:18am UTC](https://discourse.julialang.org/t/is-this-a-bug-relevant-for-0-4-6/4030/2 "2017-06-01T11:18:53Z")

</div>

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

```julia
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
0.5

```

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

---

<div class="post-metadata">

**Author:** ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)\
**Post date:** [June 1, 2017, 12:56pm UTC](https://discourse.julialang.org/t/is-this-a-bug-relevant-for-0-4-6/4030/3 "2017-06-01T12:56:13Z")

</div>

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:

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

```

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…

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [June 1, 2017, 1:22pm UTC](https://discourse.julialang.org/t/is-this-a-bug-relevant-for-0-4-6/4030/4 "2017-06-01T13:22:57Z")

</div>

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
julia> beta = 3
3

julia> workspace()

julia> beta
bbeta (generic function with 4 methods)

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

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

```

---

<div class="post-metadata">

**Author:** ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)\
**Post date:** [June 1, 2017, 5:32pm UTC](https://discourse.julialang.org/t/is-this-a-bug-relevant-for-0-4-6/4030/5 "2017-06-01T17:32:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Rudolf\_Sykora](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@Rudolf\_Sykora](https://discourse.julialang.org/u/Rudolf_Sykora)\
**Post date:** [June 1, 2017, 5:50pm UTC](https://discourse.julialang.org/t/is-this-a-bug-relevant-for-0-4-6/4030/6 "2017-06-01T17:50:35Z")

</div>

> [@Per](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![Rudolf\_Sykora](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@Rudolf\_Sykora](https://discourse.julialang.org/u/Rudolf_Sykora)\
**Post date:** [June 6, 2017, 7:45am UTC](https://discourse.julialang.org/t/is-this-a-bug-relevant-for-0-4-6/4030/7 "2017-06-06T07:45:52Z")

</div>

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

Thanks!  
Ruda

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [June 6, 2017, 9:17am UTC](https://discourse.julialang.org/t/is-this-a-bug-relevant-for-0-4-6/4030/8 "2017-06-06T09:17:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [June 6, 2017, 9:19am UTC](https://discourse.julialang.org/t/is-this-a-bug-relevant-for-0-4-6/4030/9 "2017-06-06T09:19:30Z")

</div>

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

```julia
for i1=1:2
end

```

should change anything to the behavior of the program.

---

<div class="post-metadata">

**Author:** ![Rudolf\_Sykora](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@Rudolf\_Sykora](https://discourse.julialang.org/u/Rudolf_Sykora)\
**Post date:** [June 6, 2017, 9:41am UTC](https://discourse.julialang.org/t/is-this-a-bug-relevant-for-0-4-6/4030/10 "2017-06-06T09:41:47Z")

</div>

> [@dpsanders](#):
>
> Are you aware that there is (was) a function called beta, which is what you are seeing?

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

Thanks  
Ruda

---

<div class="post-metadata">

**Author:** ![Rudolf\_Sykora](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@Rudolf\_Sykora](https://discourse.julialang.org/u/Rudolf_Sykora)\
**Post date:** [June 6, 2017, 9:45am UTC](https://discourse.julialang.org/t/is-this-a-bug-relevant-for-0-4-6/4030/11 "2017-06-06T09:45:35Z")

</div>

> [@nalimilan](#):
>
> 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  
> end
> 
> should change anything to the behavior of the program.

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.

Ruda

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [June 6, 2017, 12:43pm UTC](https://discourse.julialang.org/t/is-this-a-bug-relevant-for-0-4-6/4030/12 "2017-06-06T12:43:58Z")

</div>

[https://github.com/JuliaLang/julia/issues/21989](https://github.com/JuliaLang/julia/issues/21989)
