LuaLS / LuaLS/lua-language-server

[Feature request] Implicit casts for common conversions

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

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

主要言語
Lua
スター
4.4k
フォーク
442
PR マージ指標
30日以内にマージされた PR はありません

説明

I got some code for parsing command line flags/user inputs that commonly uses patterns like this

---@return string ...
local function strsplit(str, sep) end

local a, b, c = strsplit(userinput, ",")
b = tonumber(b) or 0 -- error:  This variable is defined as type `string`. Cannot convert its type to `number`

The fix is to define b as string|number in the declaration, but it's a bit cumbersome, especially if I just want b as a number:

local a,
---@type number|string
b, c = strsplit(userinput, ",")

So it would be nice if common type conversion patterns like this could be recognized automatically and either allow the cast or infer the type as string|number from the beginning.

Edit: See comment below, the implicit cast is already happening, this is really about type inference based on later assignments. Which may or may not be a good idea.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、issue に記載されている既存の implicit-cast と type-inference の挙動を追跡します。特に、後続の代入が以前の変数宣言にどのような影響を与えるかを確認します。意図する推論ルールを定義し、コマンドライン解析の例に照らして検証します。合意された挙動が定まり、その結果推論される型をカバーするテストがあれば完了です。

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

評価

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

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

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