Script Analysis does not warn about using locals in the statement they are defined in

The following code does not trigger any warnings in Script Analysis:

local A = function()

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()

Despite the variable con not being defined in this function, Script Analysis will not have any warnings.

Yup, that’s a bug and the reason is precisely described in your post. Will fix.

1 Like


1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.