lua-language-server
lua-language-server copied to clipboard
Support for a bottom type for non-returning functions
How are you using the lua-language-server?
Visual Studio Code Extension (sumneko.lua)
Which OS are you using?
Windows
What is the issue affecting?
Type Checking
Expected Behaviour
Have a way to tag the return type of a function as Bottom, i.e., never returns.
Actual Behaviour
I have a snippet like this:
local function abort(err)
io.stderr:write(err .. "\n")
os.exit(1)
end
local function stuff()
local chunk = loadfile("x.lua")
if not chunk then
abort("failed to loadfile()")
end
chunk()
return {}
end
stuff()
which triggers the "need-nil-check" diagnostic on "chunk()" because it doesn't understand that abort() never returns, so i would like to tag abort() (or better tag os.exit() and do return os.exit) as never returning function.
obvious work-around is to do "return abort(...)" instead, but that messes up the return type of stuff() from table to table|nil. so i have to write abort() return {} to make the type checker happy which is a bit cumbersome
Reproduction steps
- Go to '...'
- Click '...'
- See error '...'
Additional Notes
No response
Log File
No response
See https://github.com/LuaLS/lua-language-server/issues/1881 for a similar request.