Skip to content

@overload return union unexpected behaviour #3078

@AgatZan

Description

@AgatZan

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions