Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overload intellise prototype issue with meta functions #2709

Open
Rathoz opened this issue Jun 12, 2024 · 2 comments
Open

Overload intellise prototype issue with meta functions #2709

Rathoz opened this issue Jun 12, 2024 · 2 comments

Comments

@Rathoz
Copy link
Contributor

Rathoz commented Jun 12, 2024

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Windows

What is the issue affecting?

Type Checking

Expected Behaviour

type of b should be string

Actual Behaviour

type of b is string|nil

Reproduction steps

---@meta
local Foo = {}
---@overload fun(a: string): string
---@overload fun(a: number): table
function Foo.Bar(a)
end

local b = Foo.Bar('abc') -- type of is `string|nil`

Additional Notes

image

Log File

No response

@tomlau10
Copy link
Contributor

I think that's because you did not define the base type of the function, so LuaLs just infer the base type by itself, that this empty function can return nil. To workaround this, you may change one of the ---@overload declaration into ---@param and ---@return:

---@meta
local Foo = {}

---@param a string
---@return string
---@overload fun(a: number): table
function Foo.Bar(a)
end

local b = Foo.Bar('abc') -- type of is `string` now

@Rathoz
Copy link
Contributor Author

Rathoz commented Jun 13, 2024

I know why it happens and I know that there's a workaround ;)

Doesn't mean it shouldn't be bug reported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants