I never used FastClosures so I won’t comment on that, but the original code’s methods are actually not quite the same. In fnc!, F, P belonged entirely to the method’s scope, but in Fnc!, F, P actually belonged to return_fnc’s scope, it’s just that nested local scopes share variables when assigned (this is usually a useful behavior but may not be what you intended). return_fnc knows the type of F, P going in, but it can’t possibly predict the type of F, P because it is reassigned in the body of Fnc! that hasn’t even been called yet. That’s why F, P is type-unstable across both Fnc! and return_fnc. Just this edit:
...
Fnc! = (q, x, y, p) -> begin
local F, P # declared different from the outer F, P!!!
F, P = p
...
makes the methods’ @code_warntype equivalent. Not sure if the performance would be exactly the same, the global fnc! is implicitly const while the global Fnc! isn’t.