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

Lua Language Server Fails to Infer Type When Passing Multiple Return Values to Generic Function #3007

Open
Isrothy opened this issue Dec 26, 2024 · 0 comments

Comments

@Isrothy
Copy link

Isrothy commented Dec 26, 2024

How are you using the lua-language-server?

NeoVim

Which OS are you using?

MacOS

What is the issue affecting?

Type Checking

Expected Behaviour

---@return integer
---@return string
local f = function()
	return 1, "a"
end

---@generic T
---@generic U
---@param t T
---@param u U
---@return U
local g = function(t, u)
	return u
end

local x = g(f())

When the function g is called with the multiple return values of f, the Lua Language Server should infer the type of x based on the second return value of f (string), corresponding to the second generic type parameter (U) in g.

Actual Behaviour

The Lua Language Server fails to infer the type of x. Instead, the type is left unknown.

Reproduction steps

  1. Write the following Lua code in an editor with the Lua Language Server enabled:
---@return integer
---@return string
local f = function()
	return 1, "a"
end

---@generic T
---@generic U
---@param t T
---@param u U
---@return U
local g = function(t, u)
	return u
end

local x = g(f())
  1. Observe the type inference for x.
  2. Note that the type of x is not inferred as string as expected.

Additional Notes

No response

Log File

No response

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

1 participant