# Strange behavior in defining function

**URL:** <https://discourse.julialang.org/t/strange-behavior-in-defining-function/80271>\
**Category:** General Usage\
**Tags:** functions\
**Created:** [April 29, 2022, 7:35pm UTC](https://discourse.julialang.org/t/strange-behavior-in-defining-function/80271 "2022-04-29T19:35:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![neujmin1](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@neujmin1](https://discourse.julialang.org/u/neujmin1)\
**Post date:** [April 29, 2022, 7:35pm UTC](https://discourse.julialang.org/t/strange-behavior-in-defining-function/80271/1 "2022-04-29T19:35:46Z")

</div>

Had a “gotcha” that I don’t understand the behavior of. Bug maybe, or am I missing something here??

Here’s a simplified code example…

“”"  
function foo()

```
 wookie = false

 f(x) = 5

 if wookie
    println("wookie activated")
    f(x) = 4
 end

 println(f(1))

```

end

“”"

4 is what gets printed out.

and my versioninfo…

versioninfo()  
Julia Version 1.7.2  
Commit bf53498635 (2022-02-06 15:21 UTC)  
Platform Info:  
OS: Linux (x86\_64-pc-linux-gnu)  
CPU: Intel(R) Core™ i7-9700K CPU @ 3.60GHz  
WORD\_SIZE: 64  
LIBM: libopenlibm  
LLVM: libLLVM-12.0.1 (ORCJIT, skylake)

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [April 29, 2022, 7:39pm UTC](https://discourse.julialang.org/t/strange-behavior-in-defining-function/80271/2 "2022-04-29T19:39:45Z")

</div>

See [https://github.com/JuliaLang/julia/issues/15602#issuecomment-226518246](https://github.com/JuliaLang/julia/issues/15602#issuecomment-226518246)

---

<div class="post-metadata">

**Author:** ![neujmin1](https://avatars.discourse-cdn.com/v4/letter/n/d2c977/32.png) [@neujmin1](https://discourse.julialang.org/u/neujmin1)\
**Post date:** [April 29, 2022, 8:12pm UTC](https://discourse.julialang.org/t/strange-behavior-in-defining-function/80271/3 "2022-04-29T20:12:29Z")

</div>

Cool, thanks for the fast reply! I’m glad there’s a solution and that this is known. Seems non-intuitive, but I’ll keep the workaround in mind.

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [April 29, 2022, 8:19pm UTC](https://discourse.julialang.org/t/strange-behavior-in-defining-function/80271/4 "2022-04-29T20:19:38Z")

</div>

Yeah, it really should be an error. It currently gives a warning, but it’s not an obvious one.
