LuaLS / LuaLS/lua-language-server
`@overload` return union unexpected behaviour
Open
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?
NeoVim
Which OS are you using?
Windows
What is the issue affecting?
Type Checking, Diagnostics/Syntax Checking
Expected Behaviour
Type of r1 = EA|0
Not warning: probably nil
Actual Behaviour
Type of r1 = integer|EA|0
Warning: probably nil
Reproduction steps
- Create file
test.lua - Fill
---@enum EA
local EA = {
a = 1,
b = 2,
}
local ab = 0
---@overload fun(): 0
---@overload fun(): EA, [string]
local function fua()
if ab == 0 then
return 0
else
return EA[ab] or EA.a, { "aa" }
end
end
local r1, r2 = fua()
if r1 == 0 then
print(0)
else
print(r2[1])
end
- See type of
r1 - See
Need check nilat line 22
Additional Notes
Maybe duplicate of #1456
Log File
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 by reproducing the report in test.lua with the supplied @overload example and inspect the inferred types and diagnostic at line 22. Done means r1 is inferred as EA|0 and the nil warning is no longer reported for the shown control flow.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100