You can spot global variables in functions with reflection, even something as simple as:
julia> foo() = sin(x) # oops I forgot to write `foo(x)`
foo (generic function with 1 method)
julia> @code_warntype foo()
MethodInstance for foo()
from foo() in Main at REPL[12]:1
Arguments
#self#::Core.Const(foo)
Body::Any
1 ─ %1 = Main.sin(Main.x)::Any
└── return %1
But you need to distinguish the intended globals like Main.sin
or the unintended globals like Main.x
. You don’t have to do this much work if you get the habit of writing all the necessary arguments into a function header, it’s a good habit in any language.