LuaLS / LuaLS/lua-language-server

string|nil passed to string parameter not flagged as error with strict settings

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

还没有人认领这个 Issue。

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

描述

How are you using the lua-language-server?

Command Line

Which OS are you using?

Linux

What is the issue affecting?

Type Checking

Expected Behaviour

With the following config (see below), I expect Lua Language Server to report a type mismatch when passing a string|nil value to a function that expects a non-optional string parameter.

Specifically, this line should raise a diagnostic:

test_func(params.ip) -- where params.ip is string|nil, but test_func expects string
Actual Behaviour

No error is reported by LLS, neither in VS Code nor when using the CLI with --check.

Reproduction steps
  1. Save this code in a .lua file:
---@class TestParams
---@field ip string | nil

---@param ip string
---@return string
local function test_func(ip)
    return ip
end

---@type TestParams
local params = { ip = nil }

test_func(params.ip)

  1. Use the following lua-language-server config (.luarc.json or through your client):
{
  "runtime": {
    "version": "Lua 5.1"
  },
  "diagnostics": {
    "enable": true,
    "disable": [],
    "groupFileStatus": {
      "ambiguity": "Any",
      "await": "Any",
      "codestyle": "Any",
      "duplicate": "Any",
      "global": "Any",
      "luadoc": "Any",
      "redefined": "Any",
      "strict": "Any",
      "strong": "Any",
      "type-check": "Any",
      "unbalanced": "Any",
      "unused": "Any"
    },
    "groupSeverity": {
      "ambiguity": "Error",
      "await": "Error",
      "codestyle": "Error",
      "duplicate": "Error",
      "global": "Error",
      "luadoc": "Error",
      "redefined": "Error",
      "strict": "Error",
      "strong": "Error",
      "type-check": "Error",
      "unbalanced": "Error",
      "unused": "Error"
    }
  },
  "type": {
    "weakNilCheck": false
  }
}
  1. Run the CLI:
lua-language-server-3.15.0-linux-x64/bin/lua-language-server --check your_file.lua

Or use VS Code extension.

Additional Notes

No response

Log File
Diagnosis completed, no problems found

贡献指南

打开贡献指南

从这里开始

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

调研方向

从提供的 Lua 复现代码和 .luarc.json 开始,然后运行文档中记录的 lua-language-server --check 命令,以确认缺少该诊断。跟踪函数参数的类型检查路径并添加回归覆盖;完成的标准是将参数 string|nil 报告为与所需的 string 参数不兼容。

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

评估

技术栈
lua
领域
tooling
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
38/100

把新 issue 发到你的邮箱

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