Packages icon indicating copy to clipboard operation
Packages copied to clipboard

[Lua] Function mis-scope

Open Resike opened this issue 2 years ago • 3 comments

What happened?

Special case function definition gets scoped to string:

local x = {
    func1 = not false and function(...) end or nil, -- func1 is `string.unquoted.key.lua`
    func2 = function(...) end, -- func2 is `entity.name.function.lua`
}

Both function (func1 and func2) definition should be entity.name.function.lua

Resike avatar Sep 17 '23 20:09 Resike

Trying to determine whether func1 in func1 = not false and function(...) end or nil is a function is too generic of a problem to be solved on a syntax definition level, because you'd need to properly parse the expression and evaluate all possibilities whether one of them could end up with a function object.

FichteFoll avatar Sep 18 '23 08:09 FichteFoll

Yeah honestly I don't have a proper solution for this, that's why i created the ticket, but it just could be not solvable.

Resike avatar Sep 18 '23 17:09 Resike

Not an lua expert, but as func1 is scoped as dictionary key, I wonder why func2 is not.

deathaxe avatar Sep 18 '23 19:09 deathaxe