FPtje / GLuaFixer

Linter for Garry's mod Lua.
https://fptje.github.io/glualint-web/
GNU Lesser General Public License v2.1
142 stars 19 forks source link

local heythere(n) = heythere(num) bug #177

Closed Srlion closed 8 months ago

Srlion commented 9 months ago

Hey there!

local heythere(n) = heythere(num)

just throws a warning Unnecessary parentheses

Also prettier formats it into:

local heythere
n = heythere(num)

Appreciate your work, thank you for taking the time to make the linter!

FPtje commented 9 months ago

Thanks for the report! That's an odd one. I'll look at it when I have time 👍

FPtje commented 8 months ago

So the above is not allowed, but this apparently is:

local a = {"whoa"}
local foo(a)[1] = a[1]
print("yeah this works, ", foo, ", ", a[1])

It means this:

local a = {"whoa"}
local foo
a[1] = a[1]
print("yeah this works, ", foo, ", ", a[1])
Srlion commented 8 months ago

It’s because you are turning it into a statement and lua doesn’t use semicolons to end statements so it just works lol.

it expects an equal sign for local statement, but it found a parentheses so it ended the local statement and moved on, just like you can’t write (function() end) but you can write (function end)() I wrote a lua parser in lua before and it was fun, just followed: https://www.lua.org/manual/5.1/manual.html

FPtje commented 8 months ago

That manual has been my guide as well, but throughout the years, people just find odd edge cases. Following the manual is one thing, being precisely equal to what the Lua code itself does is something else. I added an explicit check to disallow this case :+1: