[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [ANN] Luacheck 0.19.0
- From: Peter Melnichenko <mpeterval@...>
- Date: Sat, 4 Mar 2017 00:11:28 +0300
On Fri, Mar 3, 2017 at 10:10 PM, Peter Aronoff <email@example.com> wrote:
> That said, I now wonder about something more general. When people write in
> Lua `local x = y or z`, that’s often an idiom for cases where y is likely
> to be nil. Or, at least, where y can be nil, but the program should
> continue without trouble by assigning z to x instead of y. In my mind, it
> isn’t clear whether this *should* trigger a warning, since presumably the
> programmer puts that “or z” in there to address the danger of y being nil.
> Thanks, Peter
> We have not been faced with the need to satisfy someone else's
> requirements, and for this freedom we are grateful.
> Dennis Ritchie and Ken Thompson, The UNIX Time-Sharing System
Yes, it would be more convenient if this idiom was recognized. But there
should still be a warning if the global variable is definitely incorrect, e.g.
`local load = loadstringgg or load`. So that means that Luacheck would
need a new class of defined globals that can only be accessed through
this idiom. It already distinguishes read-only and settable globals
so it shouldn't be difficult to implement this.
Some minor problems: strange things like
`local load = loadstring or table.unpack` will be allowed, while
variations of the idiom like
`local unpack = unpack ~= nil and unpack or table.unpack` won't.