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

Two Rule Suggestions: multiple returns in function calls / table definitions and string concatenation #2699

Open
chrisgrieser opened this issue Jun 6, 2024 · 0 comments

Comments

@chrisgrieser
Copy link

chrisgrieser commented Jun 6, 2024

multiple returns in function calls / table definitions

local a = { "one", "two", "three" }
local b = { unpack(a), "four" }
local c = { "four", unpack(a) }
print(#b) -- 2
print(#c) -- 4

unpack's behavior is quite unintuitive; when the output is not in the last position of a table definition, only the first element is actually included in the new table. (In fact, this not only applies to unpack, but to every function that returns multiple values – only happens most often with unpack that will people will notice, I assume.)

see explainer in the docs: https://www.lua.org/manual/5.3/manual.html#3.4

I think a diagnostic that reminds one of such cases would be very useful, since it's a common gotcha in lua.

string concatenation

print("foo" + "bar")

Common mistake to not use .. for string concatenation. Even though I am used to lua, it still happens to me all the time after coming back from writing in a different language. A diagnostic here would be useful. (And I am actually a bit surprised that there isn't one yet.)

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

No branches or pull requests

1 participant