lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

`@overload` return union unexpected behaviour

Open AgatZan opened this issue 8 months ago • 4 comments

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

  1. Create file test.lua
  2. 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
  1. See type of r1
  2. See Need check nil at line 22

Additional Notes

Maybe duplicate of #1456

Image

Log File

Log file

AgatZan avatar Feb 14 '25 21:02 AgatZan