LuaLS / LuaLS/lua-language-server

[Feature Request] Required nullable arguments

オープン
#2,070 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

リポジトリのファイルやテストは指定されていません。まず、Lua関数およびJava/Kahlua呼び出しに関係するアノテーション処理と引数数の解決のパスを特定します。提案されている ?!!?! の形式を比較し、その後、省略された引数と明示的な nil 引数に対するカバレッジを定義し、実装前に意図した構文を確認します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
lua
領域
devtools
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。