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):
---@param self objectPoolManager
---@param tmxId integer
---@param map string
---@return boolean
function objectPoolManager:hasTmxObject(tmxId, map)
return self.objectRefTable[map] ~= nil and self.objectRefTable[map][tmxId] ~= nil
end
and it gives error:
Annotations specify that return value #1 has a type of `boolean`, returning value of type `boolean` here instead.
I have to downgrade all the way to 3.4.2 to make this error disappear. what am I doing wrong? the error message is completely nonsensical
@firas-assaad if you could explain me what should be done since you asked for this change
@sumneko if you can provide a fix or explain what is wrong in the code and what I need to change that can help, im pretty sure more people will have the same doubt
@dganzella I don't think your issue is related to this one (which was fixed long ago). I suggest creating a new issue with additional information and a longer example (where objectRefTable is defined, for example).
I don't get any errors with your example but it might depend on how objectRefTable is defined.
@dganzella I don't think your issue is related to this one (which was fixed long ago). I suggest creating a new issue with additional information and a longer example (where objectRefTable is defined, for example).
I don't get any errors with your example but it might depend on how objectRefTable is defined.
Activity
#1294 fix operator `and`/`or` for boolean
dganzella commentedon Sep 10, 2025
I really do not understand this.
I have this method in my code
and it gives error:
Annotations specify that return value #1 has a type of `boolean`, returning value of type `boolean` here instead.I have to downgrade all the way to 3.4.2 to make this error disappear. what am I doing wrong? the error message is completely nonsensical
@firas-assaad if you could explain me what should be done since you asked for this change
@sumneko if you can provide a fix or explain what is wrong in the code and what I need to change that can help, im pretty sure more people will have the same doubt
firas-assaad commentedon Sep 16, 2025
@dganzella I don't think your issue is related to this one (which was fixed long ago). I suggest creating a new issue with additional information and a longer example (where objectRefTable is defined, for example).
I don't get any errors with your example but it might depend on how
objectRefTableis defined.dganzella commentedon Sep 30, 2025
will do. at least im not crazy haha.
Thanks!