Skip to content

generics narrowing type too much #2922

@Bilal2453

Description

@Bilal2453

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Linux

What is the issue affecting?

Type Checking, Completion

Expected Behaviour

---
---Returns a random (index, value) pair from an array-like table.
---
---@generic V
---@param tbl {[any]: V}
---@return number, V
---@nodiscard
function extensions.table.randomipair(tbl) end

local _, a = extensions.table.randomipair({1, 'a', false})
print(a) --> integer|string|boolean

Actual Behaviour

---
---Returns a random (index, value) pair from an array-like table.
---
---@generic V
---@param tbl {[any]: V}
---@return number, V
---@nodiscard
function extensions.table.randomipair(tbl) end

local _, a = extensions.table.randomipair({1, 'a', false})
print(a) --> 1

image

Reproduction steps

Paste the above reproduction code and press ctrl + space on a.

Additional Notes

Tested on v3.8.1.

Log File

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions