Strange behavior in defining function

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




4 is what gets printed out.

and my 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
LIBM: libopenlibm
LLVM: libLLVM-12.0.1 (ORCJIT, skylake)

See disallow methods of local functions in different blocks · Issue #15602 · JuliaLang/julia · GitHub

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.

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