VSCode-EmmyLua
VSCode-EmmyLua copied to clipboard
Scoping bug when combining local with function assignment
I suspect it is because I define a function using a local variable that should be then considered local function but it ends up placed in the global scope.
Very interesting. Test4 was defined as local, then it temporary becomes global, because you define a new global function with the same name and it overwrite local variable, so at the end it is local again, but emmylua "remember" that it was global.
Technically you're right, it's a bug (maybe), but you use a very weird way to define this function. You should use
local function Test4() end
instead of
local Test4
function Test4() end
Even if it's really a bug, I like it, because it helps to don't write shitty code :D
Thanks for taking time to look into this ticket.
The origin for this was purely accidental. Sometimes I use(d) this technique to scope variables out of the rest of the code like:
local MyFunc do
local internalReusableVariables
local internalFuncs() end
function MyFunc(i) end
end
Purely to have MyFunc exposes as a local to the file scope but have the other internal variables and functions in their own scope to limit autocomplete madness if the file got some size and a lot of these were supposed to not be used elsewhere outside that particular function anyway.