You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When variable a has a truthy type (e.g. any type that does not contain boolean or nil), then the following lines should all give warnings, since (assuming the type annotations are correct and Weak Nil Check is off) a cannot be nil or false, and thus can never resolve to false in a boolean context, and so the operations are pointless:
ifathenprint("1") end-- will always print 1ifnotathenprint("2") end-- will never print 2localb=aor"3" -- equivalent to b = alocalc=aand"4" or"5" -- equivalent to c = "4"
Actual Behaviour
None of those lines warn you about anything under the current diagnostics
(I would also like a "no-unparameterized-tables" diagnostic where plain table without any <> does not count as a valid type)
mycroftjr
changed the title
Needs a "don't use truthy types in a conditional/boolean context" check
Needs a "don't use truthy types in a conditional/boolean context" diagnostic
Apr 13, 2024
How are you using the lua-language-server?
Visual Studio Code Extension (sumneko.lua)
Which OS are you using?
Windows
What is the issue affecting?
Type Checking, Diagnostics/Syntax Checking
Expected Behaviour
When variable
a
has a truthy type (e.g. any type that does not containboolean
ornil
), then the following lines should all give warnings, since (assuming the type annotations are correct andWeak Nil Check
is off)a
cannot benil
orfalse
, and thus can never resolve tofalse
in a boolean context, and so the operations are pointless:Actual Behaviour
None of those lines warn you about anything under the current diagnostics
Reproduction steps
The text was updated successfully, but these errors were encountered: