fix: support Lua 5.5 prefix local attributes#3393
fix: support Lua 5.5 prefix local attributes#3393Ne9roni wants to merge 1 commit intoLuaLS:masterfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for Lua 5.5 prefix local attributes, such as local <close>x. The changes involve updating the parser to handle both prefix and suffix attributes, merging them during variable creation, and implementing validation for the <close> attribute across Lua 5.4 and 5.5. A review comment suggested refactoring the logic for identifying variables without attributes into a helper function to enhance code readability.
| local extra | ||
| if n2 and not n2.attrs then | ||
| extra = n2 | ||
| elseif nrest then | ||
| for i = 1, #nrest do | ||
| if not nrest[i].attrs then | ||
| extra = nrest[i] | ||
| break | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
This block of code to find the first variable without attributes could be extracted into a helper function to improve the readability and maintainability of checkLocalCloseList.
For example, you could create a helper function like this:
local function findFirstVarWithoutAttrs(n2, nrest)
if n2 and not n2.attrs then
return n2
end
if nrest then
for i = 1, #nrest do
if not nrest[i].attrs then
return nrest[i]
end
end
end
return nil
endThen, this block could be simplified to a single line:
local extra = findFirstVarWithoutAttrs(n2, nrest)
Summary
Fix parser support for Lua 5.5 prefix local attributes in local declarations.
This fixes valid Lua 5.5 code such as:
which was previously reported as invalid syntax.
Changes
localdeclarations forLua 5.5local <attr> function ...forms<close>/<const>Notes
While validating this change against the Lua 5.5 compiler, I found that the previous test expectation around multiple
<close>variables in a single local declaration was incorrect.Lua 5.5 allows prefix local attributes, but it does not allow multiple to-be-closed variables in the same local declaration list. This PR updates the parser behavior and tests to match the actual Lua 5.5 compiler behavior.