The following code does not trigger any warnings in Script Analysis:
local A = function()
print(A)
end
However, inside the function, A
is not yet defined. The scope of a local
variable does not include the declaration itself. This is discussed in the local functions section of PIL.
If print(A)
were replaced with print(undefined)
you would get a warning, Unknown global ‘undefined’. The fact that the above code does not trigger a warning is confusing, and is probably a bug in Script Analysis’s local variable scope rules.
A case where the above can’t be rewritten to use the local function
sugar would be an event which wants to disconnect itself:
local con = event:connect(function()
con:disconnect()
end)
Despite the variable con
not being defined in this function, Script Analysis will not have any warnings.