tl icon indicating copy to clipboard operation
tl copied to clipboard

Compiler option to warn when non-boolean values used in if statements

Open svermeulen opened this issue 7 months ago • 2 comments

After using teal daily for years, I find that one of the most common mistakes I make is accidentally doing something like

local record Foo
   bar: boolean
end

local foo:Foo = {
   bar = false
}

if foo then
   print("true")
else
   print("false")
end

When I meant to do this:

if foo.bar then
   print("true")
else
   print("false")
end

Teal happily type checks this first code even though foo is a table and not a bool. I suspect most users like this because it's so common to do nil checks, but I would much rather require a strict "if foo == nil then" if I could have teal catch these mistakes instead

svermeulen avatar Jul 04 '25 06:07 svermeulen

Related: https://github.com/teal-language/tl/pull/46

svermeulen avatar Jul 04 '25 06:07 svermeulen

also related: #598

Frityet avatar Jul 04 '25 07:07 Frityet