Type unstable function because same variable name used twice

Yes, that boxing is done by the frontend and is exactly performance of captured variables in closures · Issue #15276 · JuliaLang/julia · GitHub. Note that the type stability of y is irrelevant here, for example:

function f(x)
    y = "a"
    y = "b"
    g(_) = y 
    return g(x)
end

will also cause a Box.

4 Likes