LuaLS / LuaLS/lua-language-server

Detect functions that never return (and @noreturn annotation)

未关闭
#1,881 4 条评论 5 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

enhancement
主要语言
Lua
星标
4.4k
派生
442
PR 合并指标
30 天内没有已合并 PR

描述

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:

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.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

Issue 中没有指定文件或测试。首先跟踪 nil 检查警告以及现有的 @nodiscard 注解处理,然后确定应如何表示不返回的内置函数、自定义函数和 @noreturn;当示例不再发出警告且注解行为得到覆盖时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
lua
领域
devtools
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。