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
{{ message }}
Repository navigation
Needs a "don't use truthy types in a conditional/boolean context" diagnostic #2609
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
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[/+]on Apr 13, 2024
I think the core issue isn’t just "always truthy" but that truthy/falsy itself is error‑prone.
I’d like a diagnostic (or opt‑in setting) that requires boolean‑only in conditional/boolean contexts (if/while/and/or/not, etc.).
Even when a value can be nil, allowing non‑boolean types in conditions makes intent ambiguous and makes bugs easier to miss.
A "boolean‑only condition" check would address this directly.
Activity
[-]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[/+]kyoh86 commentedon Jan 28, 2026
I think the core issue isn’t just "always truthy" but that truthy/falsy itself is error‑prone.
I’d like a diagnostic (or opt‑in setting) that requires boolean‑only in conditional/boolean contexts (if/while/and/or/not, etc.).
Even when a value can be nil, allowing non‑boolean types in conditions makes intent ambiguous and makes bugs easier to miss.
A "boolean‑only condition" check would address this directly.