LuaLS / LuaLS/lua-language-server
Detect functions that never return (and @noreturn annotation)
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
Some functions, such as `error`, never return control to the caller. This can be used to prove that a value is not nil, for example:
```lua
function my_function(input)
local value = input.value or error('Missing value')
-- The following line would currently raise a "Needs nil check" warning
-- However, if it was nil at runtime, an error would have been raised and it would never get this far.
return value:sub(1, 3)
end
```
It's not just `error` that can cause this, however. A custom function could be written that never returns as well (the most obvious way is that the function unconditionally calls `error`, but there may be other ways involving coroutines or functions implemented in C). A `@noreturn` annotation could be used to indicate this, similar to `@nodiscard`.
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
No file or test is named in the issue. Start by tracing the nil-check warning and the existing @nodiscard annotation handling, then determine how non-returning built-ins, custom functions, and @noreturn should be represented; done means the example no longer warns and the annotation behavior is covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100