LuaLS / LuaLS/lua-language-server

[Feature Request] Required nullable arguments

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

还没有人认领这个 Issue。

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

描述

When calling Java methods from Kahlua, the number of arguments is used to determine the appropriate implementation to call. Because of this, arguments that can be nil are required in the function call for appropriate resolution. This is usually not a concern in Lua, but it could be.

In this example, both f() and f(nil) are appropriate, since the value of x defaults to nil.

---@param x integer?
local function f(x) end

In this example, however, the behaviors of t.f() and t.f(nil) are not equivalent.
(Admittedly, this is a contrived example. Nonetheless, it shows that this would not only be useful for strange cases like Kahlua's implementation.)

---@class Example
---@field f fun(x: integer?)
t = {
    f = function(...)
        assert(select('#', ...) == 1)
    end
}

I don't feel strongly about the annotation that would be used to specify this, but ! comes to mind:

---@class Example
---@field f fun(x: integer?!)
t = {
    f = function(...)
        assert(select('#', ...) == 1)
    end
}

The ?!/!? pair may be redundant, since non-nil argument types are always required. It would also be feasible to represent required but nil-able arguments with ! alone.

贡献指南

打开贡献指南

从这里开始

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

调研方向

未指定任何 repository 文件或测试。首先定位与 Lua 函数和 Java/Kahlua 调用相关的注解处理路径以及参数数量解析路径。比较提议的 ?!!?! 形式,然后定义对省略参数与显式 nil 参数的覆盖范围,并在实现前确认预期的语法。

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

评估

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

把新 issue 发到你的邮箱

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