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
Describe the bug
In certain cases, boolean inferred values don't work as expected. This usually happens when calling functions that don't have explicit @return annotations and that return true or false explicitly (e.g. return false).
should_be_int is inferred as integer|true. If I annotate the function y with @return boolean or if function y is rewritten as return math.random() > 0.5, then should_be_int is correctly deduced as integer.
Example 2:
localfunctiony()
ifmath.random() <0.5thenreturntrueelsereturnfalseendend---@returnbooleanlocalfunctionx()
localbool=truebool=y()
bool=boolandy()
ifboolthenprint(1)
endreturnbool-- Warning: The type of the 1 return value is `boolean`, but the actual return is `boolean|true|false`end
The variable bool is inferred as boolean|true|false which is somehow incompatible with the specified @return. If I remove the @return annotation, or if the y function doesn't explicitly return true/false, or if you change the body of the function x, the warning does not happen.
Expected behavior
The boolean return types should be treated the same in all cases.
Screenshots
I wrote down the warnings in the code snippets, but if you want screenshots let me know.
Environment (please complete the following information):
OS: Windows 10
Is WSL remote? No
Client: VSCode 1.68.1
lua-language-server version v3.4.2
The text was updated successfully, but these errors were encountered:
Describe the bug
In certain cases, boolean inferred values don't work as expected. This usually happens when calling functions that don't have explicit
@return
annotations and that returntrue
orfalse
explicitly (e.g.return false
).To Reproduce
Example 1:
should_be_int
is inferred asinteger|true
. If I annotate the functiony
with@return boolean
or if functiony
is rewritten asreturn math.random() > 0.5
, thenshould_be_int
is correctly deduced asinteger
.Example 2:
The variable
bool
is inferred asboolean|true|false
which is somehow incompatible with the specified@return
. If I remove the@return
annotation, or if they
function doesn't explicitly returntrue/false
, or if you change the body of the functionx
, the warning does not happen.Expected behavior
The boolean return types should be treated the same in all cases.
Screenshots
I wrote down the warnings in the code snippets, but if you want screenshots let me know.
Environment (please complete the following information):
The text was updated successfully, but these errors were encountered: