Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn of mutated loop variables #109

Open
Zash opened this issue Feb 23, 2024 · 2 comments
Open

Warn of mutated loop variables #109

Zash opened this issue Feb 23, 2024 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@Zash
Copy link

Zash commented Feb 23, 2024

Lua development version has made loop variables read-only in lua/lua@b2f7b3b so having a warning for this would be good so that those cases could be found early.

E.g. code like

for i = 1, 10 do
  i = i - 1
end
for k,v in pairs({ foo = "bar" }) do
  k = "k:"..k
end

Fails with attempt to assign to const variable 'i'

@alerque alerque added enhancement New feature or request help wanted Extra attention is needed labels Feb 23, 2024
@asherber
Copy link

asherber commented May 7, 2024

Similarly, a warning when trying to explicitly assign to a const variable in 5.4.

local foo <const> = 5
foo = 6  -- should generate warning

@alerque
Copy link
Member

alerque commented May 8, 2024

Contributions welcome. I don't have a lot of time to develop this myself right now but I mostly keep up with facilitating community contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Development

No branches or pull requests

3 participants