How to detect globals (inadvertently used) in a function?

Tools for that do exist, Traceur.jl is even pointed out in the Manual in Julia’s official documentation. Currently I prefer JET.jl, though:

julia> a = 1
1

julia> f(x) = a + x
f (generic function with 1 method)

julia> using JET

julia> @report_opt f(7)
═════ 1 possible error found ═════
┌ @ REPL[2]:1 Main.+(%1, x)
│ runtime dispatch detected: Main.+(%1::Any, x::Int64)

Note that this is completely based on static analysis, but it’s possible to also use run time information with SnoopCompile.jl.

2 Likes