LuaLS / LuaLS/lua-language-server
Support for a bottom type for non-returning functions
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the type-checking path for the need-nil-check diagnostic and the existing function return-type annotations. Compare the requested handling of abort and os.exit with how the checker infers stuff() after the call. Done means a non-returning function can be represented so the nil diagnostic is avoided without adding nil to stuff()'s return type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100