teal-language / tl

The compiler for Teal, a typed dialect of Lua
MIT License
2.02k stars 101 forks source link

Incorrect "unused argument" warning when using variable arguments #737

Closed ator-dev closed 3 months ago

ator-dev commented 4 months ago

image

Expected behaviour: I would expect that the special arg variable is recognised as use of the variable arguments; if it is not present this warning should be reported, but not otherwise.

I would like to debug this myself, but could not find the source of "unused argument" anywhere across tl, cyan, teal-language-server, and vscode-teal. Would you mind directing me to the code area responsible for generating warnings? I would have guessed at the compiler, but as I said, I couldn't find the string.

Thanks for the lovely language!

hishamhm commented 4 months ago

@ator-dev arg as a function's vararg was deprecated back in 2006, see section 7.1: https://www.lua.org/manual/5.1/manual.html. The idiom for that since Lua 5.1, which Teal also adopts, is {...}. (Lua 5.1 only supports the old idiom when a compatibility flag is enabled, and those are usually dropped in later versions.)

arg nowadays is used as the global table for command-line arguments, and that use is also adopted by Teal.

I would like to debug this myself, but could not find the source of "unused argument"

Thank you for the initiative! That is not greppable because unused arguments are handled along with other unused things (variables, labels), so the final message gets concatenated.

Thanks for the lovely language!

Thank you for the kind words! I hope this incompatibility to what you're used to doesn't put you off too much. :) Teal strives to support idioms that are common to multiple Lua versions, in order to reduce incompatibility in the Lua landscape.

ator-dev commented 3 months ago

Thank you for the update! I don't know how that happened; I read up on it, and for some reason the only documentation I saw was for arg. I suppose the most prominent links in my search engine were just older ones.

Thank you for the kind words! I hope this incompatibility to what you're used to doesn't put you off too much.

No worries! Of course not, I respect what Teal is doing and I thought the arg thing was an unintuitive way of doing it anyway. It's not even something I'd used before. I remember scouring the Teal documentation (and eventually the issues) trying to find an answer; maybe there's a relevant docs section where this could be noted?

Sorry for the late reply by the way, it's kind of busy on my end.

hishamhm commented 3 months ago

I remember scouring the Teal documentation (and eventually the issues) trying to find an answer; maybe there's a relevant docs section where this could be noted?

We don't really have a "compatibility" doc, I think. Ultimately we should have a full Reference Manual at some point (probably based on Lua's) but we currently don't, so we've been building the docs little by little. Every bit helps if you want to make a docs PR contribution. :)