# Local function redefinition: feature or bug?

**URL:** <https://discourse.julialang.org/t/local-function-redefinition-feature-or-bug/10158>\
**Category:** General Usage\
**Created:** [April 4, 2018, 1:47pm UTC](https://discourse.julialang.org/t/local-function-redefinition-feature-or-bug/10158 "2018-04-04T13:47:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![longqian95](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longqian95/32/6947_2.png) [@longqian95](https://discourse.julialang.org/u/longqian95)\
**Post date:** [April 4, 2018, 1:47pm UTC](https://discourse.julialang.org/t/local-function-redefinition-feature-or-bug/10158/1 "2018-04-04T13:47:26Z")

</div>

For the followed function, t() will output 12 in Julia0.4 and output 22 since Julia0.5. Is that a feature or bug? Anyway, it looks strange to output 22 and cause a hard bug after I upgrade my some old Julia code from 0.4 to 0.6.

```julia
function t()
    f()=1
    print(f())
    f()=2
    print(f())
end

```

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [April 4, 2018, 3:16pm UTC](https://discourse.julialang.org/t/local-function-redefinition-feature-or-bug/10158/2 "2018-04-04T15:16:18Z")

</div>

Please [quote your code with backticks](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530)

This is indeed confusing and is a real change since earlier Julia versions: [https://github.com/JuliaLang/julia/issues/15602#issuecomment-200410836](https://github.com/JuliaLang/julia/issues/15602#issuecomment-200410836)

Fortunately, it’s also very easy to fix by using an anonymous function instead (which will perform just as well):

```julia
julia> function t()
         f = () -> 1
         print(f())
         f = () -> 2
         print(f())
       end
t (generic function with 1 method)

julia> t()
12

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [April 4, 2018, 3:30pm UTC](https://discourse.julialang.org/t/local-function-redefinition-feature-or-bug/10158/3 "2018-04-04T15:30:12Z")

</div>

BTW, is there any documentation in the `v0.7` manual about how function tables work in local scope?

---

<div class="post-metadata">

**Author:** ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)\
**Post date:** [April 4, 2018, 10:33pm UTC](https://discourse.julialang.org/t/local-function-redefinition-feature-or-bug/10158/4 "2018-04-04T22:33:27Z")

</div>

It could less easy with multiple dispatch:

```julia
julia> function t()
           f(x::Number)=1
           print(f(1.))
           f(x::Float64)=2
           print(f(1))
       end;t()
21

```
