Warn of mutated loop variables
Zash opened this issue · comments
Kim Alvefur commented
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'
Aaron Sherber commented
Similarly, a warning when trying to explicitly assign to a const variable in 5.4.
local foo <const> = 5
foo = 6 -- should generate warning
Caleb Maclennan commented
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.