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
I am not sure this is a duplicate issue considering how common it probably is, but just to make sure.
Possibly a duplicate of #1583.
This is similar to #1146, but with returns instead of params.
It is a common pattern in Lua that on errors you might instead return a nil value to imply failure, along side an error message.
---@returntable---@overloadfun(): nil, stringlocalfunctionfetchX() endlocalresource, fail=fetchX()
ifnotresourcethenprint(fail:sub(1, 3)) -- fail type here is expected to be "string"end
Actual Behaviour
You get a warning on fail that it might possibly be nil. Because its type is string|nil.
---@returntable---@overloadfun(): nil, stringlocalfunctionfetchX() endlocalresource, fail=fetchX()
ifnotresourcethenprint(fail:sub(1, 3) )-- fail type here is actually "string|nil"end
Reproduction steps
Copy the setup code
follow along with the comments
Additional Notes
I believe narrowing down the types in this case is still possible? It seems to me like #1583 was discussing the possibility of adding tuples, but shouldn't this be doable even without tuples support?
Log File
No response
The text was updated successfully, but these errors were encountered:
How are you using the lua-language-server?
Visual Studio Code Extension (sumneko.lua)
Which OS are you using?
Linux
What is the issue affecting?
Type Checking, Completion
Expected Behaviour
I am not sure this is a duplicate issue considering how common it probably is, but just to make sure.
Possibly a duplicate of #1583.
This is similar to #1146, but with returns instead of params.
It is a common pattern in Lua that on errors you might instead return a
nil
value to imply failure, along side an error message.Actual Behaviour
You get a warning on
fail
that it might possibly be nil. Because its type isstring|nil
.Reproduction steps
Additional Notes
I believe narrowing down the types in this case is still possible? It seems to me like #1583 was discussing the possibility of adding tuples, but shouldn't this be doable even without tuples support?
Log File
No response
The text was updated successfully, but these errors were encountered: