Skip to content

fix: support Lua 5.5 prefix local attributes#3393

Open
Ne9roni wants to merge 1 commit intoLuaLS:masterfrom
Ne9roni:fix/lua55-prefix-local-attrs
Open

fix: support Lua 5.5 prefix local attributes#3393
Ne9roni wants to merge 1 commit intoLuaLS:masterfrom
Ne9roni:fix/lua55-prefix-local-attrs

Conversation

@Ne9roni
Copy link
Copy Markdown

@Ne9roni Ne9roni commented Mar 28, 2026

Summary

Fix parser support for Lua 5.5 prefix local attributes in local declarations.

This fixes valid Lua 5.5 code such as:

local <close>x = ...
local <const>x = 1

which was previously reported as invalid syntax.

Changes

  • allow prefix local attributes in local declarations for Lua 5.5
  • keep prefix local attributes gated by runtime version
  • reject invalid local <attr> function ... forms
  • update parser tests for Lua 5.5 prefix <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.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +988 to +998
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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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
end

Then, this block could be simplified to a single line:
local extra = findFirstVarWithoutAttrs(n2, nrest)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant