LuaLS / LuaLS/lua-language-server
string|nil passed to string parameter not flagged as error with strict settings
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
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
- Save this code in a
.luafile:
---@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)
- Use the following
lua-language-server config(.luarc.jsonor 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
}
}
- 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied Lua reproducer and .luarc.json, then run the documented lua-language-server --check command to confirm the missing diagnostic. Trace the type-checking path for function arguments and add regression coverage; done means the string|nil argument is reported as incompatible with the required string parameter.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100