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 摘要。