Hello, I just stumbled across

local f = function(T::Type)

return function(x::T)

x + 1

end

end

which gives “UndefVarError: T not defined” due to the inner x::T.

This is a bit surprising to me, as using dynamic types is allowed for local, i.e. the following is ok:

local f = function(T::Type)

local x::T = 3

x + 1

end

Now, I’m aware that I could rewrite the first example with something like `eval(Expr(:function, Expr(:tuple, Expr(:(::), :x, T) ...`

, but unfortunately, in my specific use case I actually need a capture (thus breaking the eval approach due to eval’s global scope), i.e. what I actually want to achieve is this:

local y

local f = function(T::Type)

return function(x::T)

x + y

end

end

Is there any sensible to achieve this?